Skip to content

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

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

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?

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 it's also OK we handle useLatestTag before switch.

@BoYanZh BoYanZh closed this Feb 9, 2025
@BoYanZh BoYanZh deleted the badge-tag branch February 9, 2025 10:38
@go-gitea go-gitea locked as resolved and limited conversation to collaborators May 10, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. modifies/go Pull requests that update Go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants