Пример #1
0
        private static async Task <ToDoComment> GetLineNumber(ToDoComment input)
        {
            var httpClient = new HttpClient();
            var url        = $"https://raw.githubusercontent.com/{input.Repository}/{input.BranchName}/{input.Path}";
            var text       = await httpClient.GetStringAsync(url);

            var lineNumber = text.Take(input.Position).Count(c => c == '\n') + 1;

            input.LineNumber = lineNumber;
            return(input);
        }
Пример #2
0
        private static ToDoComment GetBaseToDoComment(ToDoComment input, dynamic graphQLData)
        {
            var defaultBranchRef = graphQLData.data.repository.defaultBranchRef as dynamic;
            var branchName       = defaultBranchRef.name.Value;

            return(new ToDoComment
            {
                Repository = input.Repository,
                Path = input.Path,
                Position = input.Position,
                BranchName = branchName
            });
        }
Пример #3
0
        private static async Task <dynamic> GetGraphQLData(ToDoComment input)
        {
            var owner      = input.Repository.Split("/")[0];
            var repository = input.Repository.Split("/")[1];
            var query      = "{repository(owner: \\\"" + owner + "\\\", name: \\\"" + repository + "\\\") {"
                             + " defaultBranchRef {"
                             + " name"
                             + " target {"
                             + " ... on Commit {"
                             + " history(first: 1) {"
                             + " edges {"
                             + " node {"
                             + " committedDate"
                             + "}"
                             + "}"
                             + "}"
                             + " blame(path: \\\"" + input.Path + "\\\") {"
                             + " ranges {"
                             + " startingLine"
                             + " endingLine"
                             + " commit {"
                             + " committedDate"
                             + " }"
                             + " }"
                             + " }"
                             + " }"
                             + " }"
                             + " }"
                             + " }"
                             + " }";

            var httpClient = new HttpClient();
            var url        = "https://api.github.com/graphql";
            var request    = new HttpRequestMessage
            {
                RequestUri = new Uri(url),
                Method     = HttpMethod.Post,
                Content    = new StringContent("{ \"query\": \"" + query + "\"")
            };

            request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", "");
            request.Headers.Add("User-Agent", "petermorlion");

            var response = await httpClient.SendAsync(request);

            var content = await response.Content.ReadAsStringAsync();

            dynamic data = JObject.Parse(content);

            return(data);
        }
Пример #4
0
        private static ToDoComment GetCommitDateAndAge(ToDoComment input, dynamic graphQLData)
        {
            var defaultBranchRef = graphQLData.data.repository.defaultBranchRef as dynamic;
            var branchName       = defaultBranchRef.name;
            var latestCommitDate = (DateTime)defaultBranchRef.target.history.edges[0].node.committedDate;
            var ranges           = defaultBranchRef.target.blame.ranges as IEnumerable <dynamic>;
            var range            = ranges.SingleOrDefault(r => (int)r.startingLine <= input.LineNumber && (int)r.endingLine >= input.LineNumber);
            var committedDate    = (DateTime)range.commit.committedDate;
            var ageInDays        = (latestCommitDate - committedDate).Days;

            input.CommitDate = committedDate;
            input.AgeInDays  = ageInDays;

            return(input);
        }