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

add submodule diff links #33097

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

add submodule diff links #33097

wants to merge 3 commits into from

Conversation

bohde
Copy link
Contributor

@bohde bohde commented Jan 3, 2025

This adds links to submodules in diffs, similar to the existing link when viewing a repo at a specific commit. It does this by expanding diff parsing to recognize changes to submodules, and find the specific refs that are added, deleted or changed.

The templates are updated to add either a link to the submodule at a commit, or the diff between two commits in the event that the submodule is updated.

A slight refactor was done to simplify calling RefURL on the submodule. There was also a FIXME comment in the template that said this should be updated to account for setting.AppSubURL. I tested this in an environment that uses a non default setting.AppSubURL, and verified that it works.

Related #25888

This adds links to submodules in diffs, similar to the existing link
when viewing a repo at a specific commit. It does this by expanding
diff parsing to recognize changes to submodules, and find the specific
refs that are added, deleted or changed.

The templates are updated to add either a link to the submodule at a
commit, or the diff between two commits in the event that the
submodule is updated.

A slight refactor was done to simplify calling RefURL on the
submodule.
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jan 3, 2025
@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jan 3, 2025
@github-actions github-actions bot added modifies/translation modifies/go Pull requests that update Go code modifies/templates This PR modifies the template files labels Jan 3, 2025
@bohde bohde marked this pull request as ready for review January 3, 2025 20:20
@lunny lunny added this to the 1.24.0 milestone Jan 4, 2025
@wxiaoguang
Copy link
Contributor

wxiaoguang commented Jan 4, 2025

ps: we need this one first: Make git clone URL could use current signed-in user #33091 : it make the Git URL parsing more general (parseRepositoryURL) and need to be used here to replace the getRefURL

@wxiaoguang
Copy link
Contributor

wxiaoguang commented Jan 4, 2025

Made some changes in 8d63859:

  1. avoid using HTML trick in translations
  2. hide diff-header-popup-btn for submodules, otherwise there is an empty popup-menu
  3. remove ui message from submodule's block, otherwise there are double-borders
  4. use {{- -}} to remove extra spaces, otherwise the generated HTML page contains too many unnecessary spaces

ps: need this one "Make git clone URL could use current signed-in user #33091" to rewrite RefURL.

image

Comment on lines +45 to +55
func (si *SubmoduleInfo) RefID() string {
if si.NewRefID != "" {
return si.NewRefID
}
return si.PreviousRefID
}

// RefURL guesses and returns reference URL.
func (si *SubmoduleInfo) RefURL(repoFullName string) string {
return git.NewCommitSubModuleFile(si.SubmoduleURL, si.RefID()).RefURL(repoFullName)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I have a question here: why it should introduce RefID and use the if trick? It seems quite unclear.

And for the "deletion" case, I do not think git.NewCommitSubModuleFile(si.SubmoduleURL, si.RefID()) would work because the submodule config should have been deleted? So no way to construct a link by this approach?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. modifies/go Pull requests that update Go code modifies/templates This PR modifies the template files modifies/translation size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants