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

Feature: Support workflow event dispatch via API #32059

Merged
merged 19 commits into from
Feb 9, 2025
Merged

Conversation

bencurio
Copy link
Contributor

@bencurio bencurio commented Sep 17, 2024

ref: #31765

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Sep 17, 2024
@pull-request-size pull-request-size bot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Sep 17, 2024
@github-actions github-actions bot added modifies/api This PR adds API routes or modifies them modifies/go Pull requests that update Go code labels Sep 17, 2024
@bencurio bencurio force-pushed the main branch 2 times, most recently from 727cd1f to 8814e9f Compare September 17, 2024 16:00
@pull-request-size pull-request-size bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Sep 20, 2024
@pull-request-size pull-request-size bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Oct 2, 2024
@bencurio bencurio marked this pull request as ready for review October 2, 2024 10:18
@bencurio bencurio changed the title [WIP] Feature: Support workflow event dispatch via API Feature: Support workflow event dispatch via API Oct 2, 2024
routers/api/v1/api.go Outdated Show resolved Hide resolved
services/actions/workflow.go Outdated Show resolved Hide resolved
@pull-request-size pull-request-size bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Oct 12, 2024
@lunny lunny added this to the 1.23.0 milestone Oct 21, 2024
routers/api/v1/api.go Outdated Show resolved Hide resolved
routers/api/v1/api.go Outdated Show resolved Hide resolved
@lunny lunny modified the milestones: 1.23.0, 1.24.0 Nov 6, 2024
@KodingDev
Copy link

Any updates on this?

@bencurio
Copy link
Contributor Author

bencurio commented Dec 4, 2024

I'm sorry, but due to my current workload, I don't have the capacity to handle the PR at the moment. However, if the code review is completed in full, I can address all the corrections at once. Thank you.

@lunny
Copy link
Member

lunny commented Dec 4, 2024

I'm sorry, but due to my current workload, I don't have the capacity to handle the PR at the moment. However, if the code review is completed in full, I can address all the corrections at once. Thank you.

would you mind maintainers send commits to your branch?

@bencurio
Copy link
Contributor Author

bencurio commented Dec 4, 2024

I'm sorry, but due to my current workload, I don't have the capacity to handle the PR at the moment. However, if the code review is completed in full, I can address all the corrections at once. Thank you.

would you mind maintainers send commits to your branch?

I don't mind, feel free to send commits to my branch. Editing is enabled. Thank you!

* uses all endpoints added here
* checks if disabled workflows cannot dispatch
* remove node_id
* fix path field
* test that the URL field of the workflow result is usable
* additional test for non default branch workflow
* return 200 when no workflows found, with an empty list
@ChristopherHX
Copy link
Contributor

I understand this is still WIP, but wanted to note that at the moment when using the API only the first job from the workflow is executed, but when started from the web all jobs are executed.

Could you please reevaluate this now/later?

This now uses the exact same logic for UI and api to trigger workflow_dispatch

Also non default branch workflows are now read instead of using always the workflow of the default branch (changed in 1.24.0/nightly)

Summary

  • node_id removed from api
  • workflow path now includes the workflow path to repo root (instead of only the filename)
  • integration tests for all added endpoints
    • no tests for the webui dispatch trigger path
  • workflow list now returns a different structure and uses the previously unused api struct
  • workflow dispatch logic is no longer a copy of the UI path
    • used a custom error type to preserve the UI error messages (not all scenarious tested)
    • the workflow dispatch http status for disabled workflows is not documented on GitHub Docs so currently http 500 can be changed on demand

Please let me know If you have some suggestions or ideas to improve this, until then I have currently no open points on my TODO list for this change

@eldiaboloz
Copy link
Contributor

I understand this is still WIP, but wanted to note that at the moment when using the API only the first job from the workflow is executed, but when started from the web all jobs are executed.

Could you please reevaluate this now/later?

Just tested and it is fixed now - both manual and API execute all the jobs from the workflow.

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Feb 8, 2025
Copy link
Contributor

@ChristopherHX ChristopherHX left a comment

Choose a reason for hiding this comment

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

I guess I'm now able to approve towards the lgtm bot, but didn't I changed way too much here

@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 8, 2025
@lunny lunny added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Feb 9, 2025
@lunny lunny merged commit 523751d into go-gitea:main Feb 9, 2025
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 9, 2025
@ChristopherHX
Copy link
Contributor

@bencurio I revoked my access to your fork, since this is done now. Thanks for your workflow api work.

zjjhot added a commit to zjjhot/gitea that referenced this pull request Feb 10, 2025
* giteaofficial/main:
  Feature: Support workflow event dispatch via API (go-gitea#32059)
  Remove "class-name" from svg icon (go-gitea#33540)
  Add "No data available" display when list is empty (go-gitea#33517)
  Add a option "--user-type bot" to admin user create, improve role display (go-gitea#27885)
Comment on lines +726 to +730
workflowID := ctx.PathParam("workflow_id")
if len(workflowID) == 0 {
ctx.Error(http.StatusUnprocessableEntity, "MissingWorkflowParameter", util.NewInvalidArgumentErrorf("workflow_id is required parameter"))
return
}
Copy link
Contributor

Choose a reason for hiding this comment

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

That's impossible to happen, dead code ........

Comment on lines +819 to +823
if terr, ok := err.(*actions_service.TranslateableError); ok {
msg := ctx.Locale.TrString(terr.Translation, terr.Args...)
ctx.Error(terr.GetCode(), msg, fmt.Errorf("%s", msg))
return
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We can't use locale in API.

IIRC the locale context is not properly prepared, and we never used that in code

// Checkboxes (and radio buttons) are on/off switches that may be toggled by the user.
// A switch is "on" when the control element's checked attribute is set.
// When a form is submitted, only "on" checkbox controls can become successful.
(*inputs)[name] = strconv.FormatBool(value == "on")
Copy link
Contributor

Choose a reason for hiding this comment

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

There is ctx.FormBool to handle this case, no need to comment the "on" behavior everywhere .......

Comment on lines +29 to +44
type TranslateableError struct {
Translation string
Args []any
Code int
}

func (t TranslateableError) Error() string {
return t.Translation
}

func (t TranslateableError) GetCode() int {
if t.Code == 0 {
return http.StatusInternalServerError
}
return t.Code
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We should not invent a new error system at the moment .........

@wxiaoguang
Copy link
Contributor

Could we revert this change and propose a new and clear PR?


URL := fmt.Sprintf("%s/actions/workflows/%s", ctx.Repo.Repository.APIURL(), entry.Name())
HTMLURL := fmt.Sprintf("%s/src/branch/%s/%s/%s", ctx.Repo.Repository.HTMLURL(ctx), defaultBranch, folder, entry.Name())
badgeURL := fmt.Sprintf("%s/actions/workflows/%s/badge.svg?branch=%s", ctx.Repo.Repository.HTMLURL(ctx), entry.Name(), ctx.Repo.Repository.DefaultBranch)
Copy link
Contributor

Choose a reason for hiding this comment

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

It forgets to escape ......

It would cause problems if there are special chars in names

wxiaoguang added a commit to wxiaoguang/gitea that referenced this pull request Feb 10, 2025
@wxiaoguang
Copy link
Contributor

wxiaoguang commented Feb 10, 2025

Could we revert this change and propose a new and clear PR?

-> Revert "Feature: Support workflow event dispatch via API (#32059)" #33541

@bencurio
Copy link
Contributor Author

@bencurio I revoked my access to your fork, since this is done now. Thanks for your workflow api work.

Thank you for continuing; unfortunately, I didn't have enough time to finish it at the end.

@bencurio
Copy link
Contributor Author

bencurio commented Feb 10, 2025

@wxiaoguang A more collaborative tone can be achieved by explaining the reasoning behind concerns. Focusing on the issues and suggesting alternatives helps maintain a respectful and constructive dialogue, which is essential for effective collaboration.

@wxiaoguang
Copy link
Contributor

@wxiaoguang A more collaborative tone can be achieved by explaining the reasoning behind concerns. Focusing on the issues and suggesting alternatives helps maintain a respectful and constructive dialogue, which is essential for effective collaboration.

I think I have explained some details for each review comment.

If there is still anything unclear, please point out and I will try to explain more.

Since I am not a native speaker, so I am not sure which "tone" could be more "collaborative": https://github.com/go-gitea/gitea/blob/main/CODE_OF_CONDUCT.md: Remember that people have varying communication styles and that not everyone is using their native language. (Meaning and tone can be lost in translation.)


And TBH I reviewed quite a lot of PRs (https://github.com/go-gitea/gitea/pulls?q=is%3Apr+is%3Aclosed+reviewed-by%3Awxiaoguang), usually I would assume that the readers could have some background knowledges about the problem, otherwise I need to type a lot of words again and again. And yes, if there is something unclear, I'd be happy to explain.

@bencurio
Copy link
Contributor Author

I'm not a native speaker either; in fact, I'm asking ChatGPT to translate this. Nevertheless, I'm taking the trouble to avoid offending anyone by using an appropriate style. This was also translated by ChatGPT. As far as I'm concerned, I've finished this PR because I still don't have any more time to continue, but I'm happy to hand over the repo to someone else if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/api This PR adds API routes or modifies them modifies/go Pull requests that update Go code size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants