Skip to content

fix: ensure we get correct data for prs - #7111

Merged
jedevc merged 1 commit into
dagger:mainfrom
jedevc:fix-telemetry-git-merge-data
Apr 18, 2024
Merged

jedevc merged 1 commit into
dagger:mainfrom
jedevc:fix-telemetry-git-merge-data

Conversation

@jedevc

@jedevc jedevc commented Apr 17, 2024 •

Copy link
Copy Markdown
Contributor

Fixes #6452.

Instead of messing around with a bunch of remotes, etc, we can apply this simple little trick.

GITHUB_REF contains the "the fully-formed ref of the branch or tag that triggered the workflow run" (see https://docs.github.com/en/actions/learn-github-actions/contexts#github-context).

Now, if the ref starts with "refs/pull/", it's a pull request. These usually end in "/merge", to indicate that this is the result of merging with the base branch. However, we can just swap this "/merge" for a "/head" to get the actual head - then we can grab all the interesting commit details from there.

What's really cool is that these should just all be available on the "origin" - GitHub automagically populates them for us.

@jedevc
jedevc marked this pull request as draft April 17, 2024 15:20
@jedevc
jedevc force-pushed the fix-telemetry-git-merge-data branch 7 times, most recently from 741c34c to 6dbb8a7 Compare April 17, 2024 16:24
@jedevc jedevc changed the title [DNM] fix: ensure we get correct data for prs fix: ensure we get correct data for prs Apr 17, 2024
@jedevc
jedevc marked this pull request as ready for review April 17, 2024 16:24
@jedevc
jedevc requested review from grouville, marcosnils and vito April 17, 2024 16:25
@jedevc

jedevc commented Apr 17, 2024

Copy link
Copy Markdown
Contributor Author

cc @grouville who wrote the original implementation of this in #6253.

@vito vito left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎉

Comment thread telemetry/labels.go Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Would this work?:

Suggested change
cmd = exec.Command("git", "rev-parse", "FETCH_HEAD")
cmd = exec.Command("git", "rev-parse", target)

Since this runs on the host, just trying to avoid any funny business with parallel fetches.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Aha, discovered that we can get this info out much more easily using --porcelain: https://git-scm.com/docs/git-fetch#_output.

Then we don't need to worry about the timing/etc of this.

@jedevc jedevc added this to the v0.11.2 milestone Apr 17, 2024
@grouville

Copy link
Copy Markdown
Member

Impressed, how did you find out this trick ? 🤯 I love it 👏

@grouville grouville left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

✅ Awesome

Instead of messing around with a bunch of remotes, etc, we can apply
this simple little trick.

`GITHUB_REF` contains the "the fully-formed ref of the branch or tag
that triggered the workflow run" (see https://docs.github.com/en/actions/learn-github-actions/contexts#github-context).

Now, if the ref starts with "refs/pull/", it's a pull request. These
usually end in "/merge", to indicate that this is the result of merging
with the base branch. However, we can just swap this "/merge" for a
"/head" to get the actual head - then we can grab all the interesting
commit details from there.

What's really cool is that these should just all be available on the
"origin" - GitHub automagically populates them for us.

Signed-off-by: Justin Chadwell <[email protected]>
@jedevc
jedevc force-pushed the fix-telemetry-git-merge-data branch from 6dbb8a7 to 71bd229 Compare April 18, 2024 12:54
@jedevc
jedevc merged commit f4a17fe into dagger:main Apr 18, 2024
@jedevc
jedevc deleted the fix-telemetry-git-merge-data branch April 18, 2024 13:40
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.

Potential issues introduced by fix: skip head merge commits on pull requests

3 participants