static int Main(string[] args) { if (!ParseCommandLineArguments(args)) { Console.Error.WriteLine(usage); return -1; } OutputTextWriter.WriteLine( "\"{0}\",\"{1}\",\"{2}\",\"{3}\",\"{4}\",\"{5}\",\"{6}\"", "Repository", "Subject", "Description", "Reporter", "Assignee", "Labels", "Comments"); foreach (var reposPath in ReposPaths) { var m = Regex.Match(reposPath, reposPathPattern); var repos = new GitRepos(token, apiUrl, m.Groups[1].Value, m.Groups[2].Value); foreach (var i in repos.Issues) { OutputTextWriter.WriteLine(i.CSVRecord); } } return 0; }
public void IssuesTest() { var sprint = new ScrumSprint(); var lytRepos = new GitRepos(OAuthToken, ApiUrl, "Notalib", "LYT"); var lytSprint2Milestone = lytRepos.Milestones.FirstOrDefault(m => m.Title == "Sprint 2"); Assert.IsNotNull(lytSprint2Milestone); sprint.Milestones.Add(lytSprint2Milestone); var sprintIssues = new List<GitIssue>(sprint.Issues.OrderBy(i => i.Number)); var milestoneIssues = new List<GitIssue>(lytSprint2Milestone.Issues.OrderBy(i => i.Number)); Assert.AreEqual(sprintIssues.Count, milestoneIssues.Count); for (int i = 0; i < sprintIssues.Count; i++) Assert.AreEqual(sprintIssues[i].Number, milestoneIssues[i].Number); //var obRepos = new GitRepos(OAuthToken, ApiUrl, "Notalib", "Online-backend"); //var obSprint2Milestone = obRepos.Milestones.FirstOrDefault(m => m.Title == "Sprint 2"); //sprint.Milestones.Add(obSprint2Milestone); //var e17Repos = new GitRepos(OAuthToken, ApiUrl, "Notalib", "E17"); //var e17Sprint2Milestone = e17Repos.Milestones.FirstOrDefault(m => m.Title == "Sprint 2"); //sprint.Milestones.Add(e17Sprint2Milestone); //Assert.IsTrue(sprint.Issues.Count > milestoneIssues.Count); foreach(var i in sprint.Issues) { var points = i.GetScrumPoints(); Console.WriteLine("{0}\t{1:0}\t{2}\t{3:0.0}\t{4}", i.Repos.Name, i.Number, i.Title, points.HasValue ? points.Value : 0.0, i.IsOpen?"open":"closed"); } }
private static IEnumerable<GitIssue> GetGitIssuesFromTracTsv(GitRepos repos) { var req = WebRequest.Create(tracTsvUrl); var res = req.GetResponse() as HttpWebResponse; if (res == null) { throw new ApplicationException("Could not load trac tsv issues from "+tracTsvUrl); } if (res.StatusCode!=HttpStatusCode.OK) { throw new ArgumentException(String.Format( "Could not load trac tsv issues from {0}: Status code {1} - {2}", tracTsvUrl, res.StatusCode, res.StatusDescription)); } var tsvStream = res.GetResponseStream(); if (tsvStream == null) return new GitIssue[0]; var reader = new CsvReader(new StreamReader(tsvStream), true, '\t', '"', '"', '#', ValueTrimmingOptions.All) {SupportsMultiline = true}; var fieldHeaders = reader.GetFieldHeaders().ToList(); if (fieldHeaders.Count == 0) return new GitIssue[0]; int issueIndex = reader.GetFieldIndex("ticket"); int summaryIndex = reader.GetFieldIndex("summary"); int descriptionIndex = reader.GetFieldIndex("_description"); int statusIndex = reader.GetFieldIndex("status"); var labelFieldIndexes = new string[] {"type", "component", "version", "severity", "priority"} .Select(reader.GetFieldIndex) .Where(i => i > -1) .ToList(); var gitIssues = new List<GitIssue>(); var labels = repos.Labels; while (reader.ReadNextRecord()) { var i = new GitIssue(repos) { Title = (summaryIndex > -1) ? reader[summaryIndex] : "", IsOpen = true, Body = ((descriptionIndex > -1) ? reader[descriptionIndex] : "").Replace("\r", "").TrimEnd(new[] {'\n', ' ', '\t'}) }; if (issueIndex > -1) { int no; if (Int32.TryParse(reader[issueIndex], out no)) { i.Number = no; } i.Body += "\n\nTrac issue " + reader[issueIndex]; } if (statusIndex > 0) { if (reader[statusIndex]=="closed") i.IsOpen = false; } foreach (var label in labels.Where(l => labelFieldIndexes.Any(index => l.Name == reader[index]))) i.Labels.Add(label); gitIssues.Add(i); } return gitIssues.OrderBy(i => i.Number); }
public void GetApiRawResult() { var gb = new GitRepos(OAuthToken, "https://api.github.com", "Notalib", "dtbookOxygen"); var res = gb.GetApiRawResult("/repos/Notalib/dtbookOxygen/issues?state=open,closed"); var o = JArray.Parse(res); var issues = o.Aggregate("", (ii, i) => String.Format("{0}#{1}:{2};\n", ii, i["number"], i["title"])); int count = o.Count(); Console.WriteLine("Found {0} issues: {1}", count, issues); }
private GitRepos GetGitRepos(String language, string orderBy, string orderDirection) { StringBuilder query = new StringBuilder(); query.Append($"q=language:{language}&sort={orderBy}&order={orderDirection}"); string uri = $"{Configuration.GetSection("GitUrl").Value}search/repositories?{query.ToString()}"; GitRepos repositories = GitHttpService.Get <GitRepos>(uri); return(repositories); }
private void UpdateCache(GitRepos repos) { CleanCache(repos); foreach (var repo in repos.Repositories) { Cache.AddOrUpdate(repo.Id, repo, (key, oldRepo) => { if (repo.UpdatedAt > oldRepo.UpdatedAt) { return(repo); } return(oldRepo); }); } }
public void GetIssuesTest() { var repos = new GitRepos(OAuthToken, "https://api.github.com", "Notalib", "dtbookOxygen"); var issues = repos.Issues; int openCount = 0; int closedCount = 0; var comments = issues.First().Comments; foreach (var i in issues) { if (i.IsOpen) { openCount++; } else { closedCount++; } } Assert.IsTrue(openCount > 0); Assert.IsTrue(closedCount == 0); }
private void CleanCache(GitRepos repos) { var set = new Dictionary <int, GitRepo>(); var removeSet = new List <int>(); foreach (var repo in repos.Repositories) { set.Add(repo.Id, repo); } foreach (var repo in Cache) { if (!set.ContainsKey(repo.Key)) { removeSet.Add(repo.Key); } } foreach (var id in removeSet) { Cache.Remove(id, out GitRepo value); } }
/// <summary> /// Constructor setting the <see cref="GitRepos"/> to which the milestone belongs /// </summary> /// <param name="r">The <see cref="GitRepos"/> to which the milestone belongs</param> public GitMilestone(GitRepos r) { if (r == null) throw new ArgumentNullException("r"); repos = r; }
/// <summary> /// Load a collection of <see cref="GitMilestone"/>s from a json array /// </summary> /// <param name="jsonIssues">The json array</param> /// <param name="parentRepos">The <see cref="GitRepos"/> to which the issues belong</param> /// <returns>The loaded <see cref="GitMilestone"/> collection</returns> public static ICollection<GitMilestone> LoadFromJson(JArray jsonIssues, GitRepos parentRepos) { return LoadFromJson(jsonIssues, () => new GitMilestone(parentRepos)); }
/// <summary> /// Constructor setting the <see cref="GitRepos"/> to which the issue belongs /// </summary> /// <param name="r">The <see cref="GitRepos"/> to which the issue belongs</param> public GitIssue(GitRepos r) { Repos = r; }
public MainWindow() { InitializeComponent(); GitRepos = new GitRepos(); }
public async Task <IActionResult> GitRepositories([FromQuery] string[] lang) { List <GitRepoDTO> listRepos = new List <GitRepoDTO>(); try { var client = _clientFactory.CreateClient("github"); foreach (var lng in lang) { var response = await client.GetAsync(requestRepos + $"?q=language:{lng}&sort=stars&order=desc"); response.EnsureSuccessStatusCode(); listRepos.Add(await response.Content.ReadAsAsync <GitRepoDTO>()); } List <Item> listItems = new List <Item>(); //Record this repo infos in database using EF using (var db = new AteliwareContext()) { //Get All repos items separately foreach (var repoUnit in listRepos) { foreach (var itemUnit in repoUnit.items) { listItems.Add(itemUnit); } } //Get just repos which are not in DB var notindbYet = from b in listItems where !(from c in db.GitRepositories select c.gitID) .Contains(b.id) select b; foreach (var recRepo in notindbYet) { GitRepos lnewrepo = new GitRepos() { gitID = recRepo.id, description = recRepo.description, name = recRepo.name, SearchDate = DateTime.Now, stars = recRepo.stargazers_count, url = recRepo.html_url, language = recRepo.language }; db.GitRepositories.Add(lnewrepo); await db.SaveChangesAsync(); } } } catch (HttpRequestException exc) { return(BadRequest(exc.Message)); } return(Ok(listRepos)); }
/// <summary> /// Loads a collection of labels from a json array of their github json representations /// </summary> /// <param name="jsonIssues">The json array</param> /// <param name="parentRepos">The parent <see cref="GitRepos"/> of the labels</param> /// <returns>The loaded collection</returns> public static IEnumerable<GitLabel> LoadFromJson(JArray jsonIssues, GitRepos parentRepos) { return LoadFromJson(jsonIssues, () => new GitLabel(parentRepos)); }
/// <summary> /// Constructor setting the <see cref="GitRepos"/> to which the label belongs /// </summary> /// <param name="r">The <see cref="GitRepos"/> to which the label belongs</param> public GitLabel(GitRepos r) { Repos = r; }