Skip to content

Conversation

@mengmichael1
Copy link
Contributor

@mengmichael1 mengmichael1 commented Nov 30, 2021

Description

Adding the ListPullRequestsWithCommit API into the backend module's available Github APIs.

https://docs.github.com/en/rest/reference/repos#list-pull-requests-associated-with-a-commit

GET /repos/{owner}/{repo}/commits/{commit_sha}/pulls

As part of Lyft's internal extensions for Clutch, we are building a new dashboard to track k8s resources deployed for integrated testing purposes. One of the columns we'd like to surface for our users is the Github PR's branch name, hyperlinked to the Github PR's URL. This allows engineers to have a single-pane-of-glass view over their test deployments of pre-merged Github PR's. The only metadata baked into the k8s artifact is the SHA of the PR, so this API will enable us to translate that into more helpful information (HTML URL, branch name) when engineers are doing their routine maintenance/management.

Testing Performed

Added unit tests. First time contributing so seeking advice on what other testing techniques can be used for this type of change :)

GitHub Issue

n/a

TODOs

n/a at the time of this posting

@github-actions
Copy link

github-actions bot commented Dec 7, 2021

This PR has been marked as stale after 7 or more days of inactivity. Please have a maintainer add the on hold label if this PR should remain open. If there is no further activity or the on hold label is not added, this PR will be closed in 3 days.

@github-actions github-actions bot added the stale Issue hasn't had activity in awhile label Dec 7, 2021
@github-actions github-actions bot closed this Dec 10, 2021
@mengmichael1 mengmichael1 reopened this Dec 14, 2021
@mengmichael1 mengmichael1 marked this pull request as ready for review December 14, 2021 19:15
@mengmichael1 mengmichael1 requested a review from a team as a code owner December 14, 2021 19:15
@mengmichael1 mengmichael1 added area: backend Backend changes and removed stale Issue hasn't had activity in awhile labels Dec 14, 2021
}, nil
}

func (s *svc) ListPullRequestsWithCommit(ctx context.Context, ref *RemoteRef, sha string) ([]*PullRequestInfo, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

i would expand the signature a bit so this could be used to query for more than just open PRs in the future without a breaking signature change.

fake edit: according to https://docs.github.com/en/rest/reference/repos#list-pull-requests-associated-with-a-commit it doesn't accept state as a parameter though, so maybe the comment below is incorrect.

Copy link
Contributor Author

@mengmichael1 mengmichael1 Dec 14, 2021

Choose a reason for hiding this comment

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

Good point. Upon looking again, seems like go-github has some contradicting information.

Here (https://github.com/google/go-github/blob/ff33a554ef2c24c1710238b69942fe51e70d89da/github/pulls.go#L121-L123) PullRequestListOptions, which is the opts part of ListPullRequestsWithCommit(ctx context.Context, owner, repo, sha string, opts *githubv3.PullRequestListOptions) states that Default State filter is "open".

However, the method comment here https://github.com/google/go-github/blob/master/github/pulls.go#L168-L194 seems to imply that the default is open and closed.

I'll see if I can find out more.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Following up with go-github here google/go-github#2228

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added in a filter for all PRs :)

1f45288

Copy link
Contributor

Choose a reason for hiding this comment

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

I think Daniel was suggesting supporting either PullRequestListOptions in the signature so that callers could specify this.

Copy link
Contributor Author

@mengmichael1 mengmichael1 Dec 21, 2021

Choose a reason for hiding this comment

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

ahh I see, I jumped the gun too quickly

done -- added in state string into the signature so the githubv3 PullRequestListOptions struct is abstracted away for callers. wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

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

imo the PR list options object is gives the most flexibility for users of the service without having to change / amend the function signature.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah ok fair point. Done -- d36be40

@mengmichael1
Copy link
Contributor Author

Addressed both comments, ready for another pass :)

@mengmichael1
Copy link
Contributor Author

I'm out for the weekend, back next week, but would really appreciate a review whenever you get the chance @dschaller @danielhochman :)

}, nil
}

func (s *svc) ListPullRequestsWithCommit(ctx context.Context, ref *RemoteRef, sha string) ([]*PullRequestInfo, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think Daniel was suggesting supporting either PullRequestListOptions in the signature so that callers could specify this.

@github-actions
Copy link

This PR has been marked as stale after 7 or more days of inactivity. Please have a maintainer add the on hold label if this PR should remain open. If there is no further activity or the on hold label is not added, this PR will be closed in 3 days.

@github-actions github-actions bot added the stale Issue hasn't had activity in awhile label Dec 29, 2021
@github-actions github-actions bot closed this Jan 3, 2022
@danielhochman danielhochman reopened this Jan 5, 2022
@danielhochman danielhochman added on hold and removed stale Issue hasn't had activity in awhile labels Jan 5, 2022
@mengmichael1
Copy link
Contributor Author

ptal @dschaller @danielhochman

@dschaller
Copy link
Contributor

lgtm - You'll need another +1 from Daniel

@danielhochman danielhochman merged commit fe77b1f into main Jan 18, 2022
@danielhochman danielhochman deleted the add-list-pr-gh-api branch January 18, 2022 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants