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

Implement actions badge svgs #28102

Merged
merged 36 commits into from Feb 27, 2024
Merged

Implement actions badge svgs #28102

merged 36 commits into from Feb 27, 2024

Conversation

lng2020
Copy link
Member

@lng2020 lng2020 commented Nov 17, 2023

replace #27187
close #23688
The badge has two parts: label(workflow name) and message(action status). 5 colors are provided with 7 statuses.
Color mapping:

var statusColorMap = map[actions_model.Status]string{
	actions_model.StatusSuccess:   "#4c1",    // Green
	actions_model.StatusSkipped:   "#dfb317", // Yellow
	actions_model.StatusUnknown:   "#97ca00", // Light Green
	actions_model.StatusFailure:   "#e05d44", // Red
	actions_model.StatusCancelled: "#fe7d37", // Orange
	actions_model.StatusWaiting:   "#dfb317", // Yellow
	actions_model.StatusRunning:   "#dfb317", // Yellow
	actions_model.StatusBlocked:   "#dfb317", // Yellow
}

preview:
1
2
3
4
5

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Nov 17, 2023
@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 17, 2023
@lng2020 lng2020 added the type/feature Completely new functionality. Can only be merged if feature freeze is not active. label Nov 17, 2023
@lng2020 lng2020 changed the title Implenment actions badge svgs Implement actions badge svgs Nov 17, 2023
@silverwind
Copy link
Member

Very nice, even without dependencies 👍

@lng2020

This comment was marked as outdated.

@silverwind
Copy link
Member

silverwind commented Nov 17, 2023

The go-badge library you mentioned is not suitable for our case

I guess the only difference is that the library probably supports more styling options, but that can be added later.

Is this will cause a License problem

I assume this counts as "Derivative Works" which is allowed in their Apache 2.0 Licence. I would put a comment and link to original repo like this. Not sure if worth it to include a full copy of the license as well, but if we follow it strictly, we should.

@lng2020

This comment was marked as outdated.

@silverwind
Copy link
Member

Some docs on this would be nice, like this.

models/actions/run.go Outdated Show resolved Hide resolved
templates/shared/actions/runner_badge.tmpl Outdated Show resolved Hide resolved
routers/web/repo/actions/badge.go Outdated Show resolved Hide resolved
routers/web/web.go Outdated Show resolved Hide resolved
Comment on lines 113 to 115
gF := float64(defaultOffset)
lW := float64(drawer.MeasureString(label)>>6) + gF
mW := float64(drawer.MeasureString(message)>>6) + gF
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it right to do so (guessing font size)?

The SVG uses font-family="Geneva,DejaVu Sans,sans-serif", do you really know its width on client side?

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 there is no way knowing how wide it would render on a client, but as long as these approximations work on common clients, I can accept them.

@KN4CK3R
Copy link
Member

KN4CK3R commented Feb 12, 2024

@lng2020 Are you still working on this PR?

@lng2020
Copy link
Member Author

lng2020 commented Feb 12, 2024

Sorry. I thought this one was replaced by #28585. But it turns out that one was closed last month.

@lng2020 Are you still working on this PR?

Would you like to take over or would you like me to finish? I can solve most reviews above except the client-side font problem.

Is it right to do so (guessing font size)?
The SVG uses font-family="Geneva,DejaVu Sans,sans-serif", do you really know its width on client side?

Or this PR can be replaced by a more well-designed badge system, which includes more badges like issue status.

@yp05327
Copy link
Contributor

yp05327 commented Feb 13, 2024

So the problem now is that do we need an internal badge system?
If we do, I think the benefit is that users can easily use it without considering the authorization problems for private repos and no internet access instances.

ps: tried the service mentioned above, it works, but not all things supported.
https://img.shields.io/gitea/issues/closed/gitea/gitea-docusaurus?gitea_url=https://gitea.com

@silverwind
Copy link
Member

I think as a start, we can serve just the action badges, more can come later if there is demand and I think this PR lays a good base, so let's get it finished.

@yp05327
Copy link
Contributor

yp05327 commented Feb 27, 2024

Longer label name more empty space:
image

@wxiaoguang
Copy link
Contributor

Longer label name more empty space:

I think it is good enough for daily usage. Why end users need so long a label.

@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Feb 27, 2024
@lunny lunny added this to the 1.22.0 milestone Feb 27, 2024
@lng2020
Copy link
Member Author

lng2020 commented Feb 27, 2024

Longer label name more empty space

As expected. The function calculates the text length is

func (m Message) TextLength() int {
	return int(float64(m.width-defaultOffset) * 9.5)
}

So the text width is only about 95% of the whole width. If the text is long, the remaining 5% will become noticeable.

@lunny lunny added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Feb 27, 2024
@GiteaBot
Copy link
Contributor

@lng2020 please fix the merge conflicts. 🍵

@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Feb 27, 2024
docs/content/usage/badge.en-us.md Outdated Show resolved Hide resolved
modules/badge/badge.go Show resolved Hide resolved
modules/badge/badge.go Outdated Show resolved Hide resolved
Co-authored-by: delvh <dev.lh@web.de>
@lng2020 lng2020 added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Feb 27, 2024
@silverwind silverwind merged commit db545b2 into go-gitea:main Feb 27, 2024
26 checks passed
@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Feb 27, 2024
zjjhot added a commit to zjjhot/gitea that referenced this pull request Feb 29, 2024
* giteaofficial/main: (23 commits)
  Fix wrong test usage of `AppSubURL` (go-gitea#29459)
  Improve contrast on blame timestamp, fix double border (go-gitea#29482)
  Fix/Improve `processWindowErrorEvent` (go-gitea#29407)
  Apply compact padding to small buttons with svg icons (go-gitea#29471)
  Fix counter display number incorrectly displayed on the page (go-gitea#29448)
  Fix incorrect user location link on profile page (go-gitea#29474)
  Fix workflow trigger event bugs (go-gitea#29467)
  Fix URL calculation in clone input box (go-gitea#29470)
  Remove jQuery from the "find file" page (go-gitea#29456)
  Move generate from module to service (go-gitea#29465)
  The job should always run when `if` is `always()` (go-gitea#29464)
  Recolor dark theme to blue shade (go-gitea#29283)
  Let ctx.FormOptionalBool() return optional.Option[bool] (go-gitea#29461)
  Implement actions badge svgs (go-gitea#28102)
  Fix missed return (go-gitea#29450)
  Use tailwind instead of `gt-[wh]-` helper classes (go-gitea#29423)
  Lock issues and pulls faster (go-gitea#29436)
  Allow to change primary email before account activation (go-gitea#29412)
  Update docs about `DEFAULT_ACTIONS_URL` (go-gitea#29442)
  Only use supported sort order for "explore/users" page (go-gitea#29430)
  ...
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/docs size/L Denotes a PR that changes 100-499 lines, ignoring generated files. type/feature Completely new functionality. Can only be merged if feature freeze is not active.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add badge for Gitea Actions to display result in README.md
9 participants