Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Record RSL entry for all pushes #7

Merged
merged 2 commits into from
Nov 11, 2024
Merged

Record RSL entry for all pushes #7

merged 2 commits into from
Nov 11, 2024

Conversation

adityasaky
Copy link
Member

@adityasaky adityasaky commented Oct 23, 2024

Fixes #6

@adityasaky
Copy link
Member Author

This needs testing still.

internal/webhook/webhook.go Show resolved Hide resolved
internal/webhook/webhook.go Outdated Show resolved Hide resolved
internal/webhook/webhook.go Outdated Show resolved Hide resolved
@adityasaky adityasaky force-pushed the record-all-pushes branch 4 times, most recently from 817c3a3 to 3c83611 Compare October 30, 2024 19:07
@adityasaky
Copy link
Member Author

There's one issue still with this. We see a pull request event and a push event when a PR is merged. For the former, we record a PR attestation and then an RSL entry for the base branch where the merge happened. With the latter, we just record an RSL entry: the intent is to model "regular pushes" to a feature branch rather than a push as a result of a PR merge. What's a straightforward way of identifying in the push event that it's actually a PR merge and not recording the RSL entry?

One option may be to hit the API for the merge commit and see if it's associated with any PRs and then inspect those to see if they were merged? But that feels expensive?

@wlynch thoughts?

Copy link
Member

@wlynch wlynch left a comment

Choose a reason for hiding this comment

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

Generally LGTM! Some minor suggestions/questions, but nothing blocking.

internal/webhook/webhook.go Show resolved Hide resolved
return err
}

cloneURL := *event.Repo.CloneURL
Copy link
Member

Choose a reason for hiding this comment

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

nit: the safer thing to do for these fields accesses (here and elsewhere) is use the getters so that we don't panic if any of the fields aren't set.

Copy link
Member Author

Choose a reason for hiding this comment

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

good shout, I'll update that.

return err
}

if err := repo.RecordRSLEntryForReference("refs/gittuf/local-ref", true, rslopts.WithOverrideRefName(*event.Ref)); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

What's the significance of local-ref here?

Copy link
Member Author

Choose a reason for hiding this comment

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

This was to be able to fetch the ref that was pushed to without having to handle cases such as the pushed branch is already checked out (default branch). It was either do this or check whether event.Ref matches the repo's default branch / currently checked out branch and skip fetch in that instance.

FWIW, we're not cloning with event.Ref as the to-be-cloned ref to also support tags cleanly, though I may have an incorrect assumption there.

@wlynch
Copy link
Member

wlynch commented Nov 8, 2024

What's a straightforward way of identifying in the push event that it's actually a PR merge and not recording the RSL entry?

I believe merged PRs you should be able to detect with their state/event type (closed).

It is possible to get associated PRs from a push commit using the graphql API, but you also need to be able to handle the possibility that a single commit can be associated with multiple PRs in various states of it being merged.

edit: you don't even need the graphql api: https://docs.github.com/en/rest/commits/commits?apiVersion=2022-11-28#list-pull-requests-associated-with-a-commit. I think if you blanket ignore closed PRs though (whether that's from a merge or a manual close) you'd still get the behavior you want and save yourself an API call.

@adityasaky
Copy link
Member Author

I believe merged PRs you should be able to detect with their state/event type (closed).

Correct, for the pull request event. However, a pull request merge also triggers a push event and we want to handle all push events except those that are a result of a pull request merge.

@adityasaky adityasaky mentioned this pull request Nov 8, 2024
@adityasaky adityasaky force-pushed the record-all-pushes branch 2 times, most recently from 0f2b364 to cbac8b4 Compare November 11, 2024 17:04
Signed-off-by: Aditya Sirish A Yelgundhalli <ayelgundhall@bloomberg.net>
Signed-off-by: Aditya Sirish A Yelgundhalli <ayelgundhall@bloomberg.net>
@adityasaky
Copy link
Member Author

adityasaky commented Nov 11, 2024

@wlynch I've added an API call to fetch PRs for the commit now. This check skips recording an entry if a PR is merged and the base branch matches the push branch.

@adityasaky
Copy link
Member Author

I'm going to merge this to deploy this to the public app (and test). I'll file a ticket to continue discussing if we can avoid the extra API call.

@adityasaky adityasaky merged commit 6a39904 into main Nov 11, 2024
2 checks passed
@adityasaky adityasaky deleted the record-all-pushes branch November 11, 2024 17:14
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.

Record RSL entry for any push
3 participants