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

Path to receive content from a repository's default branch #26920

Closed
Andre601 opened this issue Sep 5, 2023 · 3 comments · Fixed by #27384
Closed

Path to receive content from a repository's default branch #26920

Andre601 opened this issue Sep 5, 2023 · 3 comments · Fixed by #27384
Labels
good first issue Likely to be an easy fix proposal/accepted We have reviewed the proposal and agree that it should be implemented like that/at all. type/enhancement An improvement of existing functionality type/proposal The new feature has not been accepted yet but needs to be discussed first.
Milestone

Comments

@Andre601
Copy link

Andre601 commented Sep 5, 2023

Feature Description

(This has been discussed a little on the discord server)

There can be situations where you want to obtain content of a repository, but don't know the name of its default branch.

As an example, if I want to display a user profile readme in an app would I first need to obtain the repository to then get the default branch from and finally the file. This can waste API calls which, especially when unauthorized, could be somewhat limited depending on what other API requests are peformed and how frequent.

Another example could be a repository where you update the default branch whenever a new major release of your project is released, which would cause old URLs to break (Should you not keep them) or link to possible outdated sources, requiring you to update them.
With this feature could you keep the same URL and it would automatically redirect to the right file on the default branch.

Regarding the "name" of the branch would I go with ~ as it works in browsers and can't be used in a branch name itself, making it a perfect candidate to have for this function, without overriding any existing branch names a user may have.

As an example, assume a repository having a branch labeled main. Using {user}/{repo}/src/branch/~/README.md would be equal to {user}/{repo}/src/branch/main/README.md.
If the repo now has its default renamed to default would {user}/{repo}/src/branch/~/README.md now be equal to {user}/{repo}/src/branch/default/README.md

Screenshots

No response

@Andre601 Andre601 added the type/proposal The new feature has not been accepted yet but needs to be discussed first. label Sep 5, 2023
@KN4CK3R
Copy link
Member

KN4CK3R commented Sep 5, 2023

Indirect solution is to query the repo info first. There is a default_branch property.

@silverwind silverwind added the proposal/accepted We have reviewed the proposal and agree that it should be implemented like that/at all. label Sep 6, 2023
@silverwind
Copy link
Member

silverwind commented Sep 6, 2023

We should accept HEAD in place of the branch/hash, like GitHub:

https://github.com/go-gitea/gitea/blob/HEAD/README.md

in the branch dropdown, this shows as a commit ref so what GitHub is doing is just resolving the git-native HEAD reference from .git/HEAD to a hash.

Trying the same on gitea results in 404.

@silverwind
Copy link
Member

silverwind commented Sep 6, 2023

Further investigation shows Gitea has distinct URL parts /branch and /commit, unlike github which puts them together into a commit-ish on the /blob path. So I'd say HEAD be supported on at least these two paths:

/src/branch/HEAD/README.md
/src/commit/HEAD/README.md

@silverwind silverwind added the good first issue Likely to be an easy fix label Sep 6, 2023
@lunny lunny added the type/enhancement An improvement of existing functionality label Oct 2, 2023
@lunny lunny added this to the 1.22.0 milestone Oct 2, 2023
lunny pushed a commit that referenced this issue Oct 3, 2023
Add support for HEAD in paths:
```
/src/branch/HEAD/README.md
/src/commit/HEAD/README.md
```

Closes #26920
GiteaBot pushed a commit to GiteaBot/gitea that referenced this issue Oct 3, 2023
…tea#27384)

Add support for HEAD in paths:
```
/src/branch/HEAD/README.md
/src/commit/HEAD/README.md
```

Closes go-gitea#26920
lunny pushed a commit that referenced this issue Oct 3, 2023
… (#27407)

Backport #27384 by @rbhz

Add support for HEAD in paths:
```
/src/branch/HEAD/README.md
/src/commit/HEAD/README.md
```

Closes #26920

Co-authored-by: Kirill Sorokin <48334247+rbhz@users.noreply.github.com>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
good first issue Likely to be an easy fix proposal/accepted We have reviewed the proposal and agree that it should be implemented like that/at all. type/enhancement An improvement of existing functionality type/proposal The new feature has not been accepted yet but needs to be discussed first.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants