dmitri.shuralyov.com/route/github/...

Add more specific route methods to Router interface.

Split IssueURL into IssueURL and IssueCommentURL.

Split PullRequestURL into PullRequestURL and PullRequestCommentURL.

Add PullRequestReviewURL and PullRequestReviewCommentURL.
dmitshur committed 6 years ago commit ce4edef1f8c9585ca16cca2f9990a099d038c0a2
Collapse all
github.go
@@ -7,31 +7,55 @@ import (
)

// Router provides HTML URLs of GitHub subjects.
type Router interface {
	// IssueURL returns the HTML URL of the specified GitHub issue.
	IssueURL(ctx context.Context, owner, repo string, issueID, commentID uint64) string
	IssueURL(ctx context.Context, owner, repo string, issueID uint64) string

	// IssueCommentURL returns the HTML URL of the specified GitHub issue comment.
	IssueCommentURL(ctx context.Context, owner, repo string, issueID, commentID uint64) string

	// PullRequestURL returns the HTML URL of the specified GitHub pull request.
	PullRequestURL(ctx context.Context, owner, repo string, prID, commentID uint64) string
	PullRequestURL(ctx context.Context, owner, repo string, prID uint64) string

	// PullRequestCommentURL returns the HTML URL of the specified GitHub pull request comment.
	PullRequestCommentURL(ctx context.Context, owner, repo string, prID, commentID uint64) string

	// PullRequestReviewURL returns the HTML URL of the specified GitHub pull request review.
	PullRequestReviewURL(ctx context.Context, owner, repo string, prID, reviewID uint64) string

	// PullRequestReviewCommentURL returns the HTML URL of the specified GitHub pull request review comment.
	PullRequestReviewCommentURL(ctx context.Context, owner, repo string, prID, reviewCommentID uint64) string
}

// DotCom provides HTML URLs of GitHub subjects on github.com.
type DotCom struct{}

// IssueURL returns the HTML URL of the specified GitHub issue on github.com.
func (DotCom) IssueURL(_ context.Context, owner, repo string, issueID, commentID uint64) string {
	var fragment string
	if commentID != 0 {
		fragment = fmt.Sprintf("#issuecomment-%d", commentID)
	}
	return fmt.Sprintf("https://github.com/%s/%s/issues/%d%s", owner, repo, issueID, fragment)
func (DotCom) IssueURL(_ context.Context, owner, repo string, issueID uint64) string {
	return fmt.Sprintf("https://github.com/%s/%s/issues/%d", owner, repo, issueID)
}

// IssueCommentURL returns the HTML URL of the specified GitHub issue comment on github.com.
func (DotCom) IssueCommentURL(_ context.Context, owner, repo string, issueID, commentID uint64) string {
	return fmt.Sprintf("https://github.com/%s/%s/issues/%d#issuecomment-%d", owner, repo, issueID, commentID)
}

// PullRequestURL returns the HTML URL of the specified GitHub pull request on github.com.
func (DotCom) PullRequestURL(_ context.Context, owner, repo string, prID, commentID uint64) string {
	var fragment string
	if commentID != 0 {
		fragment = fmt.Sprintf("#issuecomment-%d", commentID)
	}
	return fmt.Sprintf("https://github.com/%s/%s/pull/%d%s", owner, repo, prID, fragment)
func (DotCom) PullRequestURL(_ context.Context, owner, repo string, prID uint64) string {
	return fmt.Sprintf("https://github.com/%s/%s/pull/%d", owner, repo, prID)
}

// PullRequestCommentURL returns the HTML URL of the specified GitHub pull request comment on github.com.
func (DotCom) PullRequestCommentURL(_ context.Context, owner, repo string, prID, commentID uint64) string {
	return fmt.Sprintf("https://github.com/%s/%s/pull/%d#issuecomment-%d", owner, repo, prID, commentID)
}

// PullRequestReviewURL returns the HTML URL of the specified GitHub pull request review on github.com.
func (DotCom) PullRequestReviewURL(_ context.Context, owner, repo string, prID, reviewID uint64) string {
	return fmt.Sprintf("https://github.com/%s/%s/pull/%d#pullrequestreview-%d", owner, repo, prID, reviewID)
}

// PullRequestReviewCommentURL returns the HTML URL of the specified GitHub pull request review comment on github.com.
func (DotCom) PullRequestReviewCommentURL(_ context.Context, owner, repo string, prID, reviewCommentID uint64) string {
	return fmt.Sprintf("https://github.com/%s/%s/pull/%d#discussion_r%d", owner, repo, prID, reviewCommentID)
}