Example #1
0
    // Called when the confirm button on the issue edit window is pressed - GitHub UI
    public async void EditIssue()
    {
        await GitHubManager.EditIssue(issueID, projectTracker.currentRepositoryOwner, projectTracker.currentRepositoryName, issue_title.text, issue_description.text);

        issueLoader.LoadContent();
        IssueEditedArgs args = new IssueEditedArgs(issueID, issue_title.text, issue_description.text);

        IssueEdited?.Invoke(this, args);
        Close();
    }
 protected override async Task BeforeExecutionAsync(IExecutionContext context)
 {
     if (_gitHub == null)
     {
         _gitHub = context.GetRequiredService <GitHubManager>();
     }
     if (_foundation == null)
     {
         _foundation = context.GetRequiredService <FoundationManager>();
         await _foundation.PopulateAsync(context);
     }
 }
        public async Task Test_GetUserGitHubRepo_InternalServerError()
        {
            var githubManager = new GitHubManager(_mockHttpHandler.Object);

            HttpResponseMessage message = new HttpResponseMessage();

            message.StatusCode = System.Net.HttpStatusCode.InternalServerError;

            var taskCompletion = new TaskCompletionSource <HttpResponseMessage>();

            taskCompletion.SetResult(message);
            _mockHttpHandler.Setup(n => n.GetAsync(It.IsAny <Uri>())).Returns(taskCompletion.Task);

            var result = await githubManager.GetUserGitHubRepo("SomePath", 1, 1);

            // Validate the result
            Assert.Null(result);
        }
        protected override async Task BeforeExecutionAsync(IExecutionContext context)
        {
            // Don't get data if we're just validating
            if (context.Settings.GetBool(SiteKeys.Validate))
            {
                return;
            }

            if (_gitHub == null)
            {
                _gitHub = context.GetRequiredService <GitHubManager>();
            }
            if (_foundation == null)
            {
                _foundation = context.GetRequiredService <FoundationManager>();
                await _foundation.PopulateAsync(context);
            }
        }
        public async Task Test_GetPullRequetsByRepoName_NotFound()
        {
            var githubManager = new GitHubManager(_mockHttpHandler.Object);

            HttpResponseMessage message = new HttpResponseMessage();

            message.StatusCode = System.Net.HttpStatusCode.NotFound;

            var taskCompletion = new TaskCompletionSource <HttpResponseMessage>();

            taskCompletion.SetResult(message);
            _mockHttpHandler.Setup(n => n.GetAsync(It.IsAny <Uri>())).Returns(taskCompletion.Task);

            var result = await githubManager.GetPullRequetsByRepoName("SomePath", "test");

            // Validate the result
            Assert.NotNull(result);
            Assert.Null(result.PullRequests);
        }
        public async Task Test_GetUserGitHubRepo_Success()
        {
            var githubManager = new GitHubManager(_mockHttpHandler.Object);

            HttpResponseMessage message = new HttpResponseMessage();

            message.StatusCode = System.Net.HttpStatusCode.OK;

            message.Content = new StringContent(GetUserReposData());
            var taskCompletion = new TaskCompletionSource <HttpResponseMessage>();

            taskCompletion.SetResult(message);
            _mockHttpHandler.Setup(n => n.GetAsync(It.IsAny <Uri>())).Returns(taskCompletion.Task);

            var result = await githubManager.GetUserGitHubRepo("SomePath", 1, 1);

            // Validate the result
            Assert.NotNull(result);
            Assert.NotNull(result.Repos);
            Assert.Equal(result.Repos.Count, 1);
        }
Example #7
0
    // Called when the CreateIssue button on theCreateIssue Window is pressed
    public async void CreateIssue()
    {
        switch (configurationMenu.ShelfConfiguration.SelectedSource)
        {
        case DataSource.REQUIREMENTS_BAZAAR:
            Category category;
            category = await RequirementsBazaarManager.GetCategory(projectTracker.currentCategory.id);

            Category[] categoryarray = new Category[1];
            categoryarray[0] = category;

            await RequirementsBazaarManager.CreateRequirement(projectTracker.currentProjectID, issueName.text, issueDescription.text, categoryarray);

            break;

        case DataSource.GITHUB:
            await GitHubManager.CreateIssue(projectTracker.currentRepositoryOwner, projectTracker.currentRepositoryName, issueName.text, issueDescription.text);

            break;
        }
        issueLoader.LoadContent();
        opener.CloseMenu();
    }
Example #8
0
 public void SetUp()
 {
     mockGitHubService = new Mock <IGitHubService>();
     gitHubManager     = new GitHubManager(mockGitHubService.Object);
 }
        public IHttpActionResult ConfirmWebsite(string websiteId)
        {
            ew.common.EwhLogger.Common.Debug("START CONFIRM WEBSITE: " + websiteId);
            if (ModelState.IsValid)
            {
                var ewhWebsite = _websiteManager.GetEwhWebsite(websiteId);
                if (ewhWebsite == null)
                {
                    return(NotFound());
                }
                var githubManager = new GitHubManager();
                Octokit.Repository gitRepository = null;
                //create github repository
                if (string.IsNullOrEmpty(ewhWebsite.Git))
                {
                    if (githubManager.CreateRepository(ewhWebsite.RepositoryName, ewhWebsite.DisplayName).Result)
                    {
                        gitRepository  = githubManager.RepositoryAdded;
                        ewhWebsite.Git = githubManager.RepositoryAdded.CloneUrl;
                        ewhWebsite.Save();
                    }
                    else
                    {
                        EwhLogger.Common.Debug(string.Format("Create Repository Failed: {0} - {1}", ewhWebsite.RepositoryName, ewhWebsite.DisplayName));
                        return(NoOK("Can not create github repository"));
                    }
                }
                else
                {
                    gitRepository = githubManager.GetRepository(repoName: ewhWebsite.RepositoryName).Result;
                }

                if (string.IsNullOrEmpty(ewhWebsite.Source))
                {
                    ewhWebsite.InitGogSource();
                }
                if (string.IsNullOrEmpty(ewhWebsite.Source))
                {
                    return(NoOK("Source_Empty"));
                }

                // add web-hook to demo & production server
                var ewhGogsSource     = new EwhSource();
                var ewhAccountAsOwner = _accountManager.GetEwhAccount(ewhWebsite.GetOwnerId());
                if (ewhAccountAsOwner != null)
                {
                    ewhGogsSource.CreateWebHook(new EwhSource.CreateWebHookDto(ewhAccountAsOwner.UserName, ewhWebsite.RepositoryName));

                    ewhGogsSource.CreateWebHook(new EwhSource.CreateWebHookDto(ewhAccountAsOwner.UserName, ewhWebsite.RepositoryName, ew.config.ProductionServer.WebHookUrl, ew.config.ProductionServer.SecretKey));
                }

                // create sub domain
                var websiteDomain     = string.Empty;
                var subDomainName     = string.Format("{0}-{1}.{2}", ewhAccountAsOwner.UserName, ewhWebsite.Name, ew.config.CloudflareInfo.EwhDomain).ToLower();
                var cloudflareManager = new CloudflareManager();
                if (cloudflareManager.CreateDNSRecord(ew.config.CloudflareInfo.EwhCloudflareZoneId, new cloudflare_wrapper.Models.UpdateDNSRecordDto()
                {
                    Type = "CNAME", Name = subDomainName, Content = "easywebhub.github.io"
                }))
                {
                    websiteDomain = cloudflareManager.DNSRecordAdded.name;
                }
                else
                {
                }

                if (gitRepository != null)
                {
                    var gitUrlIncludePass  = githubManager.GetGitUrlIncludePassword(ewhWebsite.Git);
                    var sourceRepoUrl      = ewhWebsite.Source;
                    var ewhGitHookListener = new EwhGitHookListener();
                    var demoGitHook        = new git_hook_listener.Models.CreateGitHookListenerConfigDto()
                    {
                        GitHookListenerBaseUrl = ew.config.DemoServer.BaseUrl,
                        repoUrl     = sourceRepoUrl,
                        branch      = "gh-pages",
                        cloneBranch = "gh-pages",
                        path        = string.Format("repositories/{0}", gitRepository.Name),
                        args        = new List <string>(),
                        then        = new List <git_hook_listener.Models.RepoCommand>()
                    };
                    demoGitHook.then.Add(new git_hook_listener.Models.RepoCommand()
                    {
                        command = "git", args = new List <string>()
                        {
                            "remote", "add", "github", gitUrlIncludePass
                        }, options = new git_hook_listener.Models.RepoCommandOption()
                        {
                            cwd = demoGitHook.path
                        }
                    });
                    demoGitHook.then.Add(new git_hook_listener.Models.RepoCommand()
                    {
                        command = "git", args = new List <string>()
                        {
                            "push", "--force", "github", "HEAD:gh-pages"
                        }, options = new git_hook_listener.Models.RepoCommandOption()
                        {
                            cwd = demoGitHook.path
                        }
                    });

                    if (ewhGitHookListener.CreateGitHookListernerConfig(demoGitHook))
                    {
                        ewhWebsite.AddStagging(new UpdateDeploymentEnvironmentToWebsite()
                        {
                            Url = websiteDomain, Git = sourceRepoUrl, HostingFee = HostingFees.Free.ToString(), Name = "EasyWeb Environment"
                        });
                    }

                    var productionGitHook = new git_hook_listener.Models.CreateGitHookListenerConfigDto()
                    {
                        GitHookListenerBaseUrl = ew.config.ProductionServer.BaseUrl,
                        repoUrl     = sourceRepoUrl,
                        branch      = "master",
                        cloneBranch = "master",
                        path        = string.Format("repositories/{0}", gitRepository.Name)
                    };
                    productionGitHook.then.Add(new git_hook_listener.Models.RepoCommand()
                    {
                        command = "git", args = new List <string>()
                        {
                            "remote", "add", "github", gitUrlIncludePass
                        }, options = new git_hook_listener.Models.RepoCommandOption()
                        {
                            cwd = productionGitHook.path
                        }
                    });
                    productionGitHook.then.Add(new git_hook_listener.Models.RepoCommand()
                    {
                        command = "git", args = new List <string>()
                        {
                            "push", "--force", "github", "gh-pages"
                        }, options = new git_hook_listener.Models.RepoCommandOption()
                        {
                            cwd = productionGitHook.path
                        }
                    });

                    if (ewhGitHookListener.CreateGitHookListernerConfig(productionGitHook))
                    {
                        ewhWebsite.AddProduction(new UpdateDeploymentEnvironmentToWebsite()
                        {
                            Git = sourceRepoUrl, HostingFee = HostingFees.Basic.ToString(), Name = "Production Enviroment"
                        });
                    }
                }
                return(Ok(new WebsiteDetailDto(ewhWebsite)));
            }
            return(BadRequest());
        }