This repository was archived by the owner on Jun 21, 2023. It is now read-only.
-
Couldn't load subscription status.
- Fork 1.2k
Add metrics for inline comments #1107
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
803787a
Added metrics for inline comments.
grokys 74139ef
Increment # inline comments opened metric.
grokys fa3001e
Post review comments via service.
grokys 5604f6a
Update metrics on post of review comment.
grokys e38cfc4
Rename PR review comment usage fields.
grokys 8927658
Added metrics for changed file context menu.
grokys File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,8 +2,11 @@ | |
| using System.Collections.Generic; | ||
| using System.ComponentModel.Composition; | ||
| using System.IO; | ||
| using System.Reactive.Linq; | ||
| using System.Threading.Tasks; | ||
| using GitHub.Factories; | ||
| using GitHub.Models; | ||
| using GitHub.Primitives; | ||
| using GitHub.Services; | ||
| using LibGit2Sharp; | ||
|
|
||
|
|
@@ -18,18 +21,24 @@ class PullRequestSessionService : IPullRequestSessionService | |
| readonly IGitService gitService; | ||
| readonly IGitClient gitClient; | ||
| readonly IDiffService diffService; | ||
| readonly IApiClientFactory apiClientFactory; | ||
| readonly IUsageTracker usageTracker; | ||
|
|
||
| readonly IDictionary<Tuple<string, string>, string> mergeBaseCache; | ||
|
|
||
| [ImportingConstructor] | ||
| public PullRequestSessionService( | ||
| IGitService gitService, | ||
| IGitClient gitClient, | ||
| IDiffService diffService) | ||
| IDiffService diffService, | ||
| IApiClientFactory apiClientFactory, | ||
| IUsageTracker usageTracker) | ||
| { | ||
| this.gitService = gitService; | ||
| this.gitClient = gitClient; | ||
| this.diffService = diffService; | ||
| this.apiClientFactory = apiClientFactory; | ||
| this.usageTracker = usageTracker; | ||
|
|
||
| mergeBaseCache = new Dictionary<Tuple<string, string>, string>(); | ||
| } | ||
|
|
@@ -125,6 +134,80 @@ public async Task<string> GetPullRequestMergeBase(ILocalRepositoryModel reposito | |
| throw new FileNotFoundException($"Couldn't find merge base between {baseSha} and {headSha}."); | ||
| } | ||
|
|
||
| /// <inheritdoc/> | ||
| public async Task<IPullRequestReviewCommentModel> PostReviewComment( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. More new methods. This this PR depend on some other PR that hasn't been merged yet? |
||
| ILocalRepositoryModel repository, | ||
| IAccount user, | ||
| int number, | ||
| string body, | ||
| string commitId, | ||
| string path, | ||
| int position) | ||
| { | ||
| var address = HostAddress.Create(repository.CloneUrl.Host); | ||
| var apiClient = await apiClientFactory.Create(address); | ||
|
|
||
| var result = await apiClient.CreatePullRequestReviewComment( | ||
| repository.Owner, | ||
| repository.Name, | ||
| number, | ||
| body, | ||
| commitId, | ||
| path, | ||
| position); | ||
|
|
||
| await usageTracker.IncrementPRReviewDiffViewInlineCommentPost(); | ||
|
|
||
| return new PullRequestReviewCommentModel | ||
| { | ||
| Body = result.Body, | ||
| CommitId = result.CommitId, | ||
| DiffHunk = result.DiffHunk, | ||
| Id = result.Id, | ||
| OriginalCommitId = result.OriginalCommitId, | ||
| OriginalPosition = result.OriginalPosition, | ||
| Path = result.Path, | ||
| Position = result.Position, | ||
| CreatedAt = result.CreatedAt, | ||
| User = user, | ||
| }; | ||
| } | ||
|
|
||
| /// <inheritdoc/> | ||
| public async Task<IPullRequestReviewCommentModel> PostReviewComment( | ||
| ILocalRepositoryModel repository, | ||
| IAccount user, | ||
| int number, | ||
| string body, | ||
| int inReplyTo) | ||
| { | ||
| var address = HostAddress.Create(repository.CloneUrl.Host); | ||
| var apiClient = await apiClientFactory.Create(address); | ||
|
|
||
| var result = await apiClient.CreatePullRequestReviewComment( | ||
| repository.Owner, | ||
| repository.Name, | ||
| number, | ||
| body, | ||
| inReplyTo); | ||
|
|
||
| await usageTracker.IncrementPRReviewDiffViewInlineCommentPost(); | ||
|
|
||
| return new PullRequestReviewCommentModel | ||
| { | ||
| Body = result.Body, | ||
| CommitId = result.CommitId, | ||
| DiffHunk = result.DiffHunk, | ||
| Id = result.Id, | ||
| OriginalCommitId = result.OriginalCommitId, | ||
| OriginalPosition = result.OriginalPosition, | ||
| Path = result.Path, | ||
| Position = result.Position, | ||
| CreatedAt = result.CreatedAt, | ||
| User = user, | ||
| }; | ||
| } | ||
|
|
||
| Task<IRepository> GetRepository(ILocalRepositoryModel repository) | ||
| { | ||
| return Task.Factory.StartNew(() => gitService.GetRepository(repository.LocalPath)); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should these methods be added as part of this PR or have they snuck in from somewhere else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They're part of the PR - I had to move things around a bit in order to be able to get hold of an
IUsageTrackerat the right place.