Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

[RFC] Parse GitHub PRs/issues in commit message#46409

Merged
philipp-spiess merged 5 commits into
mainfrom
ps/github-parse-issue-links
Jan 19, 2023
Merged

[RFC] Parse GitHub PRs/issues in commit message#46409
philipp-spiess merged 5 commits into
mainfrom
ps/github-parse-issue-links

Conversation

@philipp-spiess

@philipp-spiess philipp-spiess commented Jan 13, 2023

Copy link
Copy Markdown
Contributor

This is a proposal of a very simple way to parse git commit messages in the git blame view and link to any GitHub issues that it points to. It uses the first matching externalURL to resolve the link. This is not going to be correct for forked repos or mirrors, but might be a good quick compromise that we could ship quickly.

What are your thoughts?

Todo

  • Add GitLab support
  • Also parse commit messages in other views (commit history)

Test plan

Screenshot 2023-01-13 at 11 34 40

App preview:

Check out the client app preview documentation to learn more.

@philipp-spiess philipp-spiess requested review from a team and taras-yemets January 13, 2023 10:37
@cla-bot cla-bot Bot added the cla-signed label Jan 13, 2023
@github-actions github-actions Bot added the team/code-exploration Issues owned by the Code Exploration team label Jan 13, 2023
@sg-e2e-regression-test-bob

sg-e2e-regression-test-bob commented Jan 13, 2023

Copy link
Copy Markdown

Bundle size report 📦

Initial size Total size Async size Modules
0.00% (0.00 kb) 0.01% (+1.12 kb) 0.01% (+1.12 kb) 0.00% (0)

Look at the Statoscope report for a full comparison between the commits 5b90793 and 3c0b695 or learn more.

Open explanation
  • Initial size is the size of the initial bundle (the one that is loaded when you open the page)
  • Total size is the size of the initial bundle + all the async loaded chunks
  • Async size is the size of all the async loaded chunks
  • Modules is the number of modules in the initial bundle

@taras-yemets

Copy link
Copy Markdown
Contributor

I'm not sure if this approach is reliable.
In sourcegraph/sourcegraph repo pull request number is usually mentioned in the squash commit.
But other repositories may include GitHub/Jira/etc. issue number in the pull request name.
We are not sure whether the matching number in the commit message is a PR number, an issue number, or something totally unrelated.
For me, it seems better not to show the PR/issue link at all than to show the broken one.

@taras-yemets

Copy link
Copy Markdown
Contributor

Teams usually have contributing rules set on a repo basis (git workflow, PR names, etc.). What if we make rules for building the PR/issue/etc. links configurable on a repo basis? It may be a part of a code host configuration or something else. What do you think?

@philipp-spiess

Copy link
Copy Markdown
Contributor Author

Thanks @taras-yemets!

So yeah, first of, this is NOT the same as finding the pull request. This is just about parsing the commit title and making links for issues. Finding the pull request is another problem that requires a third-party API and proper caching and lazy loading, etc.

But other repositories may include GitHub/Jira/etc. issue number in the pull request name.

Do you have an example of this? GitHub issues and GitHub PRs have interchangeable URLs. My code handles both (e.g. this PR is also available via https://github.com/sourcegraph/sourcegraph/issues/46409).

Do you have an example of the Jira issue number? Is it common to also highlight that with a hashtag in front? I’m using Linear and the issue numbers look like this C-123 where C is a project specific shortcut. This would not match my regex.

What if we make rules for building the PR/issue/etc. links configurable on a repo basis? It may be a part of a code host configuration or something else. What do you think?

I guess we could do this but it'd be tedious to set this up. Maybe a user setting instead that we enable on dotcom (since for open source GH repos this is a common pattern)?

@philipp-spiess

Copy link
Copy Markdown
Contributor Author

I tagged a few more folks for review: All of you seem to have shown interested in this feature and I'd like to hear your ideas 🙂

@taras-yemets

Copy link
Copy Markdown
Contributor

GitHub issues and GitHub PRs have interchangeable URLs.

TIL 🙏🏻

@github-actions

Copy link
Copy Markdown
Contributor

Problem: the label i-acknowledge-this-goes-into-the-release is absent.
👉 What to do: we're in the next Sourcegraph release code freeze period. If you are 100% sure your changes should get released or provide no risk to the release, add the label your PR with i-acknowledge-this-goes-into-the-release.

@taras-yemets

Copy link
Copy Markdown
Contributor

GitHub issues and GitHub PRs have interchangeable URLs. My code handles both (e.g. this PR is also available via https://github.com/sourcegraph/sourcegraph/pull/46409).

Yes, you're right, it should work for GitHub.

Do you have an example of the Jira issue number? Is it common to also highlight that with a hashtag in front? I’m using Linear and the issue numbers look like this C-123 where C is a project specific shortcut. This would not match my regex.

I've found a few and couldn't identify a specific naming pattern ([jira-123], ABC-123, etc.). We can probably assume that #1234 in the commit message may be a GitHub issue/PR.

const before = remainingMessage.slice(0, index)

linkSegments.push(<Link {...commitLinkProps}>{before}</Link>)
linkSegments.push(<Link to={`${github.url}/issues/${issueNumber.replace('#', '')}`}>{issueNumber}</Link>)

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.

Nitpick: but linking to /pull/ (if that's interchangeable) I'd prefer, because seeing /pull/ in the browser when hovering over a URL tells me where it's going. If I see issue it would take me a few seconds to realise what's going on.

@philipp-spiess philipp-spiess changed the title [RFC] Parse GitHub issues in commit message [RFC] Parse GitHub PRs/issues in commit message Jan 16, 2023
@philipp-spiess philipp-spiess marked this pull request as ready for review January 18, 2023 15:32
@philipp-spiess

Copy link
Copy Markdown
Contributor Author

Opening this up for review, why don't we test this on dot-com and/or S2 and see how it goes? Do you think this needs a feature flag (I don't think it's super invasive so I would keep it like this)

@mrnugget mrnugget 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.

Approving without having looked at the code, but I want to see this 😬

@philipp-spiess philipp-spiess merged commit 7aee304 into main Jan 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla-signed team/code-exploration Issues owned by the Code Exploration team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants