Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@samcoe
Copy link
Contributor

@samcoe samcoe commented Jan 11, 2021

This PR adds rendering of top level pull request review comments to pr view. They are displayed inline with regular comments the same way as GitHub.com.

Screen Shot 2021-01-12 at 11 00 38 AM

Screen Shot 2021-01-12 at 11 01 00 AM

cc #1009

@samcoe samcoe self-assigned this Jan 11, 2021
@samcoe samcoe force-pushed the review-comments branch 4 times, most recently from 9daa214 to 609b3e6 Compare January 12, 2021 19:02
@samcoe samcoe marked this pull request as ready for review January 12, 2021 19:05
@samcoe samcoe requested review from ampinsk, mislav and vilmibm January 12, 2021 19:05
Copy link
Contributor

@ampinsk ampinsk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good design wise!

Copy link
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! Love the use of Comment interface.

My asks are related to ironing out some functionality, such as handling of review statuses PENDING and DISMISSED.

)

func RawCommentList(comments api.Comments) string {
type Comment interface {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great 🌟

@mislav
Copy link
Contributor

mislav commented Jan 13, 2021

@samcoe Something that I just noticed: until we have support for displaying nested comments within a review, maybe we should skip rendering COMMENTED reviews that don't have their own body. Because of our back-and-forth right now, this pr view --comments renders this thread as:

Screen Shot 2021-01-14 at 00 20 41

@samcoe samcoe requested a review from mislav January 17, 2021 19:26
@samcoe
Copy link
Contributor Author

samcoe commented Jan 17, 2021

@mislav I agree, and updated the PR to skip rendering COMMENTED reviews that don't have their own body.

Copy link
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updates look good! Only polish and possible loading optimization remains.

count := 1
go func() {
reviews, err := api.ReviewsForPullRequest(apiClient, repo, pr)
pr.Reviews = *reviews
Copy link
Contributor Author

@samcoe samcoe Jan 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a safe operation to do in the goroutine? Or should reviews be passed back to the main thread via a channel and assigned there? Same question for comments below.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Go, we will often hear the mantra: “don't communicate by sharing memory; share memory by communicating”.

Even though your current approach should work, if we follow the above mantra, it would be generally better to return the reviews and comments from goroutines via channels and assign them to the PR in the main goroutine.

However, I can't envision a case where your current code fails, and it's relatively clean, so I would also be fine if you keep it as-is.

Comment on lines 431 to 435
for i := 0; i < count; i++ {
if e := <-errc; e != nil {
err = e
}
}
Copy link
Contributor Author

@samcoe samcoe Jan 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be replicated using sync.WaitGroup.

	var wg sync.WaitGroup
	wg.Add(1)
	go func() {
		defer wg.Done()
		var reviews *api.PullRequestReviews
		reviews, err = api.ReviewsForPullRequest(apiClient, repo, pr)
		pr.Reviews = *reviews
	}()

	if opts.Comments {
		wg.Add(1)
		go func() {
			defer wg.Done()
			var comments *api.Comments
			comments, err = api.CommentsForPullRequest(apiClient, repo, pr)
			pr.Comments = *comments
		}()
	}

	wg.Wait()

	return pr, err

Are there performance implications or other downsides to this implementation? Seems like using the built in WaitGroup might be better.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call! WaitGroup is more idiomatic, so I would definitely use it here.

@samcoe samcoe requested a review from mislav January 19, 2021 21:07
Copy link
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thanks for the updates ✨

Comment on lines 431 to 435
for i := 0; i < count; i++ {
if e := <-errc; e != nil {
err = e
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call! WaitGroup is more idiomatic, so I would definitely use it here.

count := 1
go func() {
reviews, err := api.ReviewsForPullRequest(apiClient, repo, pr)
pr.Reviews = *reviews
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Go, we will often hear the mantra: “don't communicate by sharing memory; share memory by communicating”.

Even though your current approach should work, if we follow the above mantra, it would be generally better to return the reviews and comments from goroutines via channels and assign them to the PR in the main goroutine.

However, I can't envision a case where your current code fails, and it's relatively clean, so I would also be fine if you keep it as-is.

@samcoe samcoe force-pushed the review-comments branch 2 times, most recently from 7dbf28e to 6fbc5e6 Compare January 20, 2021 19:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants