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

feat: badge support tag #32451

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

feat: badge support tag #32451

wants to merge 3 commits into from

Conversation

BoYanZh
Copy link
Contributor

@BoYanZh BoYanZh commented Nov 8, 2024

Add a tag parameter to the badge.svg endpoint. When branch is empty, it will use tag to search for the workflow run. This is useful for badges for release.

e.g. https://example.com/org/repo/actions/workflows/release.yaml/badge.svg?tag=h4&event=release

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Nov 8, 2024
@pull-request-size pull-request-size bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Nov 8, 2024
@github-actions github-actions bot added the modifies/go Pull requests that update Go code label Nov 8, 2024
@lunny
Copy link
Member

lunny commented Nov 8, 2024

Maybe latest is necessary for the tag?

@BoYanZh
Copy link
Contributor Author

BoYanZh commented Nov 8, 2024

Do you mean I need to support tag=latest as a parameter and automatically find the latest tag as a ref?

@lunny
Copy link
Member

lunny commented Nov 8, 2024

Do you mean I need to support tag=latest as a parameter and automatically find the latest tag as a ref?

Or lastest_tag as a parameter to get the latest tag.

@pull-request-size pull-request-size bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Nov 9, 2024
@BoYanZh
Copy link
Contributor Author

BoYanZh commented Nov 9, 2024

Done.

var ref string
switch {
case useLatestTag:
tags, _, err := ctx.Repo.GitRepo.GetTagInfos(0, 1)
Copy link
Member

Choose a reason for hiding this comment

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

I think you should use a function like GetLatestReleaseByRepoID to do that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So we need the tag of the latest release here? Do we need to rename it to latest_release_tag?

Copy link
Member

Choose a reason for hiding this comment

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

No. All tags have been synced into databases. They shared the same table with releases.

if len(tags) != 0 {
tag = tags[0].Name
} else {
tag = "" // return empty result on no tag
Copy link
Member

Choose a reason for hiding this comment

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

If it's empty, we should return error.

ref = fmt.Sprintf("refs/tags/%s", tag)
case branch != "":
ref = fmt.Sprintf("refs/heads/%s", branch)
default:
branch = ctx.Repo.Repository.DefaultBranch
Copy link
Member

Choose a reason for hiding this comment

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

This assign statement is unnecessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I

if useLatestTag {
	tag = "xxx"
}
switch {
  // ...
}

or add a fallthrough?

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 size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants