public void TestDeletion()
        {
            var githubApi = new GithubApi(null, null, "", "");
            var processor = new LabelDifferenceProcessor(githubApi);

            var source = new List <Label>
            {
                new Label
                {
                    Name  = "label1",
                    Color = "ffffff"
                },
                new Label
                {
                    Name        = "label2",
                    Color       = "000000",
                    Description = "text"
                }
            };
            var configured = new List <Label>();

            IReadOnlyList <LabelChangeStrategy> strategies = processor.Process(source, configured);

            Assert.AreEqual(2, strategies.Count);
            Assert.IsInstanceOfType(strategies[0], typeof(LabelChangeStrategy.Remove <Label, GithubApi>));
            Assert.IsInstanceOfType(strategies[1], typeof(LabelChangeStrategy.Remove <Label, GithubApi>));
        }
Пример #2
0
        public NetkanTransformer(
            IHttpService http,
            IFileService fileService,
            IModuleService moduleService,
            string githubToken,
            bool prerelease
            )
        {
            var ghApi = new GithubApi(http, githubToken);

            _transformers = InjectVersionedOverrideTransformers(new List <ITransformer>
            {
                new MetaNetkanTransformer(http, ghApi),
                new SpacedockTransformer(new SpacedockApi(http)),
                new CurseTransformer(new CurseApi(http)),
                new GithubTransformer(ghApi, prerelease),
                new HttpTransformer(),
                new JenkinsTransformer(new JenkinsApi(http)),
                new AvcKrefTransformer(http, ghApi),
                new InternalCkanTransformer(http, moduleService),
                new AvcTransformer(http, moduleService, ghApi),
                new LocalizationsTransformer(http, moduleService),
                new VersionEditTransformer(),
                new ForcedVTransformer(),
                new EpochTransformer(),
                // This is the "default" VersionedOverrideTransformer for compatability with overrides that don't
                // specify a before or after property.
                new VersionedOverrideTransformer(before: new string[] { null }, after: new string[] { null }),
                new DownloadAttributeTransformer(http, fileService),
                new GeneratedByTransformer(),
                new OptimusPrimeTransformer(),
                new StripNetkanMetadataTransformer(),
                new PropertySortTransformer()
            });
        }
Пример #3
0
        public void Should_return_NotFound_if_email_not_exists()
        {
            var data     = new[] { Faker.Internet.Gmail() };
            var response = GithubApi.DeleteAuth("user/emails", data);

            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.NotFound));
        }
Пример #4
0
        protected override void Setup(bool usePrivateRepo)
        {
            // re-use test repo for GithubApi tests
            this.source          = new ConfigSource();
            this.source.Hoster   = "github";
            this.source.Type     = "user";
            this.source.Name     = this.GetUserName(usePrivateRepo);
            this.source.AuthName = TestHelper.EnvVar("Github_Name");
            this.source.Password = TestHelper.EnvVar("Github_PW");

            var config = new Config();

            config.Sources.Add(this.source);

            var context = new FakeContext();

            context.Config = config;

            var factory = new FakeScmFactory();

            factory.Register(ScmType.Git, new GitScm(new FileSystemHelper(), context));

            var api = new GithubApi(context, factory);

            this.repoList = api.GetRepositoryList(this.source);
            this.repo     = this.repoList.Find(r => r.ShortName == this.GetRepoName(usePrivateRepo));

            this.scm = new GitScm(new FileSystemHelper(), context);
            Assert.True(this.scm.IsOnThisComputer());

            var scmFactory = new FakeScmFactory();

            scmFactory.Register(ScmType.Git, this.scm);
            this.sut = new GithubBackup(scmFactory);
        }
        public void TestUpdate_Color()
        {
            var githubApi = new GithubApi(null, null, "", "");
            var processor = new LabelDifferenceProcessor(githubApi);

            var source = new List <Label>
            {
                new Label
                {
                    Name  = "label1",
                    Color = "ffffff"
                }
            };
            var configured = new List <Label>
            {
                new Label
                {
                    Name  = "label1",
                    Color = "ffff00"
                }
            };

            IReadOnlyList <LabelChangeStrategy> strategies = processor.Process(source, configured);

            Assert.AreEqual(1, strategies.Count);
            Assert.IsInstanceOfType(strategies[0], typeof(LabelChangeStrategy.Update <Label, GithubApi>));
        }
        public async Task RunAsync()
        {
            var prBuild = await _teamcityService.GetTeamCityBuild(_buildId);

            var prNumber = GetBranchId(prBuild.BranchName);

            if (!prNumber.HasValue)
            {
                Console.WriteLine("This build is not for a pull request");
                return;
            }

            var github = new GithubApi(_gitToken);

            foreach (var configs in _configs)
            {
                var parts            = configs.Split(':');
                var oldConfiguration = parts[0];
                var newConfiguration = parts[1];

                var oldBuildType = await _teamcityService.GetTeamCityBuildType(oldConfiguration);

                var newBuildUrl = await _teamcityService.GetTeamCityLastBuildUrlOfBuildType(newConfiguration);

                await github.SetStatusCheckAsync(prBuild.Revisions.Revision.First().Version, new StatusCheck
                {
                    State       = StatusCheckType.success,
                    TargetUrl   = newBuildUrl,
                    Description = "Deprecated - This check has been replaced by a daily build",
                    Context     = $"{oldBuildType.Name} ({oldBuildType.Project.Name})"
                });
            }
        }
Пример #7
0
        public void Should_return_NotFound_if_email_not_exists1()
        {
            var emails = GithubApi.GetAuth <List <UserEmailsResponse> >("user/emails");
            var email  = emails.First(x => x.Email.Contains("@gmail.com")).Email;

            var data     = new[] { email };
            var response = GithubApi.DeleteAuth("user/emails", data);

            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.NoContent));
        }
        public void Should_return_emails_list()
        {
            var response = GithubApi.GetAuth("user/emails");

            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
            var emails = response.DeserializeTo <List <UserEmailsResponse> >();

            Assert.That(emails.First(x => x.Primary).Email, Is.EqualTo("*****@*****.**"));
            Assert.That(emails.First(x => x.Primary).Verified, Is.True);
        }
Пример #9
0
 public DerivationChecker(DerivationOptions options)
 {
     _github      = new GithubApi(options.GithubToken);
     _teamcityApi = new TeamCityServiceClient(options.TeamCityUrl, options.TeamCityToken);
     _git         = new Git(options.Repository);
     _buildId     = options.BuildId;
     _scoped      = options.IsScoped;
     _derivation  = options.Derivation;
     _dryRun      = options.DryRun;
     _output      = options.Output;
 }
Пример #10
0
        public static ClientVersion GetClientVersion()
        {
            try
            {
                var github   = new GithubApi();
                var releases = github.GetAllReleasesInfo();

                // find my version in list
                var myVersion = releases.SingleOrDefault(arg => arg.TagName.Equals(Helper.Epg123Version));
                if (myVersion == null)
                {
                    return(new ClientVersion
                    {
                        Client = "EPG123",
                        Datetime = DateTime.UtcNow.ToLocalTime(),
                        Version = Helper.Epg123Version
                    });
                }

                // find latest release and any betas afterwords
                var latestRelease = releases.First(arg => !arg.Prerelease);
                var latestBeta    = releases.FirstOrDefault(arg => arg.PublishedAt > latestRelease.PublishedAt);
                if (myVersion.PublishedAt <= latestRelease.PublishedAt)
                {
                    if (myVersion.PublishedAt < latestRelease.PublishedAt)
                    {
                        Logger.WriteInformation($"epg123 is not up to date. Latest version is {latestRelease.TagName} and can be downloaded from {latestRelease.HtmlUrl}");
                    }
                    return(new ClientVersion
                    {
                        Client = "EPG123",
                        Datetime = latestRelease.PublishedAt.ToLocalTime(),
                        Version = latestRelease.TagName.Replace("v", "")
                    });
                }

                // return latest beta version
                if (myVersion.PublishedAt < latestBeta.PublishedAt)
                {
                    Logger.WriteInformation($"epg123 is not up to date. Latest version is {latestBeta.TagName} and can be downloaded from {latestBeta.HtmlUrl}");
                }
                return(new ClientVersion
                {
                    Client = "EPG123",
                    Datetime = latestBeta.PublishedAt.ToLocalTime(),
                    Version = latestBeta.TagName.Replace("v", "")
                });
            }
            catch (Exception ex)
            {
                Logger.WriteInformation($"GetClientVersion() Unknown exception thrown. Message: {ex.Message}");
            }
            return(null);
        }
Пример #11
0
        public ActionResult Index(string username)
        {
            IndexViewModel viewModel = new IndexViewModel();

            if (!String.IsNullOrEmpty(username))
            {
                viewModel.Username = username;
                viewModel.Repos    = GithubApi.GetRepos(username);
            }
            return(View(viewModel));
        }
Пример #12
0
        async Task <BlogInfo[]> FetchGithubBranches()
        {
            var githubApi = new GithubApi();

            if (string.IsNullOrEmpty(CurrentBlog.Token))
            {
                var githubLogin = new GithubLogin();
                githubLogin.ShowDialog();
                CurrentBlog.Token = await githubApi.GetToken(githubLogin.Code);
            }

            return(await githubApi.FetchBranches(CurrentBlog.Token, CurrentBlog.Username, CurrentBlog.WebAPI));
        }
Пример #13
0
        public void Should_add_one_email_to_profile()
        {
            var data     = "igor" + Faker.Internet.Gmail();
            var response = GithubApi.PostAuth("user/emails", data);

            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.Created));

            response = GithubApi.GetAuth("user/emails");
            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
            var emails = response.DeserializeTo <List <UserEmailsResponse> >();

            Assert.That(emails, Has.Some.Property("Email").EqualTo(data));
        }
Пример #14
0
        public void Should_add_email_to_profile()
        {
            var data = new[]
            {
                Faker.Internet.Gmail(),
                Faker.Internet.Gmail()
            };
            var response = GithubApi.PostAuth("user/emails", data);

            Assert.That(response.StatusCode,
                        Is.EqualTo(HttpStatusCode.OK),
                        "Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.Created)");
        }
Пример #15
0
        public void GetsLatestReleaseCorrectly()
        {
            // Arrange
            var sut = new GithubApi();

            // Act
            var githubRelease = sut.GetLatestRelease(new GithubRef("#/ckan/github/KSP-CKAN/Test", false, false));

            // Assert
            Assert.IsNotNull(githubRelease.Author);
            Assert.IsNotNull(githubRelease.Download);
            Assert.IsNotNull(githubRelease.Version);
        }
Пример #16
0
        public void GetsLatestReleaseCorrectly()
        {
            // Arrange
            var sut = new GithubApi(new CachingHttpService(_cache));

            // Act
            var githubRelease = sut.GetLatestRelease(new GithubRef("#/ckan/github/KSP-CKAN/Test", false, false));

            // Assert
            Assert.IsNotNull(githubRelease.Author);
            Assert.IsNotNull(githubRelease.Tag);
            Assert.IsNotNull(githubRelease.Assets.FirstOrDefault());
            Assert.IsNotNull(githubRelease.Assets.FirstOrDefault()?.Download);
        }
Пример #17
0
        public GithubEventHandler(ILogger <GithubEventHandler> logger, IOptions <GithubOptions> optionsAccessor)
        {
            _logger = logger;
            var options = optionsAccessor.Options;

            logger.LogDebug("S={server} U={user} AT={accessToken}", options.GithubApiServer, options.GithubUsername, options.GithubAccessToken);

            _api           = new GithubApi(options.GithubApiServer, options.GithubAccessToken, options.GithubOrganization, "");
            _gettingEvents = 0;
            _eventCache    = new ConcurrentDictionary <long, ApiEvent>();

            ApiEvent = _ => { };

            Initialize();
        }
Пример #18
0
        public void Should_add_double_email_to_profile()
        {
            var email    = "double" + Faker.Internet.Gmail();
            var data     = new[] { email, email };
            var response = GithubApi.PostAuth("user/emails", data);

            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.Created));

            response = GithubApi.GetAuth("user/emails");
            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
            var emails = response.DeserializeTo <List <UserEmailsResponse> >();

            Assert.That(emails.Count(x => x.Email.Equals(email)),
                        Is.EqualTo(1));
        }
Пример #19
0
        private void GetIssuesWorker(int pageFrom, int pageTo, string issuesFolderPath, GithubContext githubContext, IProgress <ProgressBundle> progress)
        {
            GithubApi githubApi = new GithubApi(githubContext);

            var queryStringDict = new Dictionary <string, string>();

            queryStringDict.Add("page", pageFrom.ToString());
            string fetchTypeString = GetStateString();

            queryStringDict.Add("state", fetchTypeString);

            ParallelOptions optionsPages  = new ParallelOptions();
            ParallelOptions optionsIssues = new ParallelOptions();

            optionsPages.MaxDegreeOfParallelism  = 2;
            optionsIssues.MaxDegreeOfParallelism = 2;
            Parallel.For(pageFrom, pageTo, optionsPages, (page, loopState) =>
            {
                var localDict     = new Dictionary <string, string>(queryStringDict);
                localDict["page"] = page.ToString();

                List <Issue> issues = githubApi.IssuesApi.Get(tbxRepoOwner.Text, tbxRepoName.Text, localDict);

                if (issues.Count == 0)
                {
                    loopState.Break();
                }

                Parallel.ForEach(issues, optionsIssues, issue =>
                {
                    List <Comment> comments = null;
                    if (cbxFetchComments.Checked)
                    {
                        comments = githubApi.CommentsApi.Get(issue);
                    }

                    SaveIssue(issue, comments, issuesFolderPath, page);

                    progress.Report(new ProgressBundle {
                        RequestsRemaining = githubContext.RequestsRemaining, UpdatePagesProgressBar = false, CountTokens = githubContext.CountTokens
                    });
                });

                progress.Report(new ProgressBundle {
                    RequestsRemaining = githubContext.RequestsRemaining, UpdatePagesProgressBar = true, CountTokens = githubContext.CountTokens
                });
            });
        }
Пример #20
0
        private async Task CheckCurrentBranch(DateTime now)
        {
            Console.WriteLine($"Checking status for build {_buildId}");
            var build = await _teamcityApi.GetTeamCityBuild(_buildId);

            var id       = GithubApi.GetBranchId(build.BranchName);
            var buildUrl = await _teamcityApi.GetTeamCityBuildUrl(_buildId, "", false);

            if (!id.HasValue)
            {
                Console.WriteLine($"{build.BranchName} is not a valid PR branch name");
                return;
            }

            var pullRequest = await _github.GetPullRequestAsync(id.Value);

            await CheckDerivationStatus(pullRequest, now, buildUrl);
        }
        public void TestSame()
        {
            var githubApi = new GithubApi(null, null, "", "");
            var processor = new LabelDifferenceProcessor(githubApi);

            var source = new List <Label>
            {
                new Label
                {
                    Name  = "label1",
                    Color = "ffffff"
                },
                new Label
                {
                    Name        = "label2",
                    Color       = "000000",
                    Description = "text"
                }
            };
            var configured = new List <Label>
            {
                new Label
                {
                    Name  = "label1",
                    Color = "ffffff"
                },
                new Label
                {
                    Name        = "label2",
                    Color       = "000000",
                    Description = "text"
                }
            };

            IReadOnlyList <LabelChangeStrategy> strategies = processor.Process(source, configured);

            Assert.AreEqual(0, strategies.Count);
        }
Пример #22
0
        public IActionResult Index(GithubInputModel inputModel)
        {
            string userName       = inputModel.UserName;
            string repositoryName = inputModel.RepositoryName;

            var mod  = new GithubResultModel();
            var json = GithubApi.GetJson(userName, repositoryName);
            GithubResultModel githubModel = null;

            try
            {
                //var b = new List<int>();
                //Console.Write(b[4]);
                githubModel = Newtonsoft.Json.JsonConvert.DeserializeObject <GithubResultModel>(json);
            }
            catch (Exception ex)
            {
                throw ex;
                //return View("Error", new ErrorViewModel { ExMessage = ex.Message, RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
            }

            return(View(githubModel));
        }
Пример #23
0
        public void Should_add_double_email_to_profil(object data)
        {
            var response = GithubApi.PostAuth("user/emails", data);

            Assert.That(response.StatusCode, Is.EqualTo((HttpStatusCode)422));
        }
Пример #24
0
 public void Should_info()
 {
     GithubApi.Get("users/ilyubin");
 }