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

perforce: Display changelists in repo and view commits page#51195

Merged
indradhanush merged 3 commits into
mainfrom
ig/perforce-changelists
May 9, 2023
Merged

perforce: Display changelists in repo and view commits page#51195
indradhanush merged 3 commits into
mainfrom
ig/perforce-changelists

Conversation

@indradhanush

@indradhanush indradhanush commented Apr 27, 2023

Copy link
Copy Markdown
Contributor

What

Part of #46488. Blocked by #51291.

We want to display the perforce changelists in the repo landing page and the view commits page instead of the commit SHA because to a perforce developer looking at this code, a commit SHA is meaningless.

Description of the changes

UI changes

For perforce depots converted to git:

  • Repo landing and the view commits pages now display changelist, changelists and changelist ID instead of commit, commits and commit SHA respectively
  • View commits page now displays the changelist ID instead of the commit SHA
  • Commit subject now displays the original changelist subject instead of the git commit message
  • Commit view page also displays the changelist related terms with changelist ID instead of the commit SHA and parent commit SHA

Also fixed the typos in the word committed across the whole codebase as I noticed it started to fail when I made a change in the existing code.

Meta UI changes

My UI skills are nascent and come with some limitations:

  • Instead of riddling the existing GitCommitNode component with if else conditions to display commit/s or changelist/s, I decided to create a new component which is pretty much a copy-paste of the GitCommitNode component with changes to display perforce terms and some minor changes to tweak the CSS and deleting some lines of code which were obviously not related to Perforce (some GitHub related checks)
  • I thought about adding an argument to the GitCommitNode to customise the message text, but I wanted to add the least amount of friction possible to the current code in case I end up breaking something, also passing changelist to a commitnode component felt wrong
  • getRefType: This function returns commit or changelist based on the repo type and I have two kinds of implementations in two different modules

I'm sure there are ways to do this cleaner in less lines of code and am happy to iterate on those. :)

Edit: I am reusing the GitCommitNode component. This was easy.

Run sg run storybook and check out the storybooks here:

image

image

image

Previously

image

image

Now

image

image

Test plan

  • Added tests
  • Added storybooks
  • Builds should pass

@cla-bot cla-bot Bot added the cla-signed label Apr 27, 2023
@sg-e2e-regression-test-bob

sg-e2e-regression-test-bob commented Apr 27, 2023

Copy link
Copy Markdown

Bundle size report 📦

Initial size Total size Async size Modules
0.00% (+0.05 kb) 0.01% (+1.37 kb) 0.01% (+1.32 kb) 0.00% (0)

Look at the Statoscope report for a full comparison between the commits 32aa12d and 86a234d 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

Comment thread cmd/frontend/graphqlbackend/git_commit.go Outdated

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.

Return the commit SHA instead of failed to parse for now. Create a GitHub issue to track this for the future. - @peterguy

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.

TODO: Test a changelist with multiple depot-paths and verify that this pattern still works for it if that's the case.

Comment thread cmd/frontend/graphqlbackend/git_commit.go Outdated
@indradhanush indradhanush force-pushed the ig/perforce-changelists branch from c72cefb to c515764 Compare April 27, 2023 16:56
@indradhanush indradhanush marked this pull request as ready for review April 27, 2023 17:48
@indradhanush indradhanush changed the title [WIP] Perforce changelists perforce: Display changelists in repo and view commits page Apr 27, 2023
@indradhanush indradhanush requested review from a team, keegancsmith and peterguy April 27, 2023 17:49
@indradhanush

Copy link
Copy Markdown
Contributor Author

@keegancsmith Requesting review for the minimal but important backend API changes.

@peterguy

Copy link
Copy Markdown
Contributor

After clicking on a particular commit in the "View changelists from this repository" view, the wording is still somewhat Git-centric. See attached screenshot. Can any of that be changed also?

Screenshot 2023-04-27 at 22 11 42

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

Amazing job!
Love the storybook coverage and backend tests 👍🏻
I agree with Peter's note about another UI view which should be covered with commit/changeset duality :)

Left some comments, PTAL.

Comment thread client/web/src/repo/changelists/PerforceDepotChangelistNodeByLine.tsx Outdated
Comment thread client/web/src/repo/changelists/PerforceDepotChangelistNodeByLine.tsx Outdated
Comment thread client/web/src/repo/commits/RepositoryCommitsPage.story.tsx Outdated
Comment thread client/web/src/repo/commits/RepositoryCommitsPage.tsx Outdated
Comment thread client/web/src/repo/tree/TreePageContent.tsx Outdated
return &repoUrl
}

var p4FusionCommitSubjectPattern = regexp.MustCompile(`^(\d+) - (.*)$`)

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.

should we use a lazyregexp here and on L492?

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.

Hmm. TIL about lazyregexp. I think I prefer using regexp.MustCompile because it will guarantee an invalid regex can never be compiled, which I think is missing with lazyregexp.

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.

Let's use lazyregexp for its benefit of being lazy and cover the validity by a unit test (which will fail in case of an invalid regex being used). Anyway, the regex is static and once it compiles during tests (during CI run) before being merged to main, we're safe in production.

WDYT?

Comment thread cmd/frontend/graphqlbackend/git_commit.go Outdated
Comment thread cmd/frontend/graphqlbackend/repository.go Outdated
Comment thread cmd/frontend/graphqlbackend/git_commit_test.go Outdated
Comment thread cmd/frontend/graphqlbackend/git_commit_test.go Outdated
@indradhanush

Copy link
Copy Markdown
Contributor Author

@peterguy, @sashaostrikov As discussed on Slack, will be following up in a new PR with updates to the commit view page.

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

Nice, LGTM!

@indradhanush

Copy link
Copy Markdown
Contributor Author

Update: The approach of modifying the the OID to return a perforce changelist ID breaks for use cases where we need to fetch details about the commit since subsequent API calls now start referring to the changelist ID as the "commit ID" which results in 404 requests.

I'm reworking the API changes, converting this to a draft and in the meantime please hold on to reviews.

@indradhanush indradhanush marked this pull request as draft May 1, 2023 09:21
@indradhanush indradhanush force-pushed the ig/perforce-changelists branch from a2ca952 to d15b441 Compare May 2, 2023 09:00
@indradhanush indradhanush changed the base branch from main to ig/perforce-changelists-api May 2, 2023 09:00
@indradhanush

indradhanush commented May 2, 2023

Copy link
Copy Markdown
Contributor Author

@peterguy, @sashaostrikov Check this out - I reused the existing component and got rid of the code duplication. All a result of the API changes I made in #51291! How cool is that?! 😎

Also that means now the commit view page also gets these improvements! See below 👇🏽👇🏽👇🏽

image

The link to the parent also works, the only downside (not in scope of this work) is that the link still works through commit SHAs so you cannot:

  1. Search by changelist ID (needs more work)
  2. Actually view what's the changelist ID when you click "browse files at this changelist"

Because the resulting page still shows up with commit SHAs.

@indradhanush indradhanush marked this pull request as ready for review May 2, 2023 14:00
@indradhanush indradhanush requested review from a team and sashaostrikov May 2, 2023 14:00
@sourcegraph-bot

sourcegraph-bot commented May 2, 2023

Copy link
Copy Markdown
Contributor

Codenotify: Notifying subscribers in CODENOTIFY files for diff d60c0c3...32aa12d.

Notify File(s)
@BolajiOlajide client/web/src/enterprise/batches/repo/BatchChangeRepoPage.story.tsx
@courier-new client/web/src/enterprise/batches/repo/BatchChangeRepoPage.story.tsx
@eseliger client/web/src/enterprise/batches/repo/BatchChangeRepoPage.story.tsx
@fkling client/branded/src/search-ui/components/CommitSearchResult.tsx
@limitedmage client/branded/src/search-ui/components/CommitSearchResult.tsx

@keegancsmith

Copy link
Copy Markdown
Member

Removing myself since there are no go changes now.

@keegancsmith keegancsmith removed their request for review May 2, 2023 14:24
@indradhanush

Copy link
Copy Markdown
Contributor Author

@keegancsmith Sorry about that. The Go changes have now moved to this PR: https://github.com/sourcegraph/sourcegraph/pull/51291.

@indradhanush indradhanush force-pushed the ig/perforce-changelists-api branch from b90ebe8 to 529c8d0 Compare May 3, 2023 10:46
Base automatically changed from ig/perforce-changelists-api to main May 4, 2023 17:18

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

hmm, I thought I already approved it after latest changes...

Approved now!

@indradhanush

Copy link
Copy Markdown
Contributor Author

hmm, I thought I already approved it after latest changes...

I need to rework this PR after the backend API changed quite a bit based on reviews in #51291.

Moving this to draft for the time being.

@indradhanush indradhanush marked this pull request as draft May 5, 2023 09:24
Co-authored-by: Milan Freml <kopancek@users.noreply.github.com>
@indradhanush indradhanush force-pushed the ig/perforce-changelists branch from 51d722d to 77f97f4 Compare May 8, 2023 17:15
@indradhanush indradhanush marked this pull request as ready for review May 9, 2023 07:02
@indradhanush indradhanush requested a review from a team May 9, 2023 07:02

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

Last fixes LGTM!

@sourcegraph-bot

Copy link
Copy Markdown
Contributor

📖 Storybook live preview

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

Took another look! 👍🏻

@indradhanush indradhanush merged commit fe73c1d into main May 9, 2023
@indradhanush indradhanush deleted the ig/perforce-changelists branch May 9, 2023 07:31
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants