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

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

Conversation

bencurio
Copy link

@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
@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 Sep 20, 2024
@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 Sep 24, 2024
Signed-off-by: Bence Santha <[email protected]>
@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
Signed-off-by: Bence Santha <[email protected]>
return
}
workflows, err := jobparser.Parse(content)
if err != nil || len(workflows) == 0 {
Copy link
Member

Choose a reason for hiding this comment

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

This will panic if err == nil.

Copy link
Author

Choose a reason for hiding this comment

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

I fixed it by adding a check for both the error and the empty workflows case. Now, it handles the scenario where len(workflows) == 0 after confirming that err == nil, preventing a potential panic.

Signed-off-by: Bence Santha <[email protected]>
@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
m.Put("/{workflow_id}/disable", reqToken(), reqChecker, actw.DisableWorkflow)
m.Post("/{workflow_id}/dispatches", reqToken(), reqChecker, bind(api.CreateActionWorkflowDispatch{}), actw.DispatchWorkflow)
m.Put("/{workflow_id}/enable", reqToken(), reqChecker, actw.EnableWorkflow)
}, context.ReferencesGitRepo(), reqRepoWriter(unit.TypeActions))
Copy link
Member

Choose a reason for hiding this comment

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

GET methods just need reqRepoReader(unit.TypeActions), POST and PUT needs reqRepoWriter(unit.TypeActions).

@@ -1107,6 +1123,11 @@ func Routes() *web.Router {
reqOwner(),
repo.NewAction(),
)
addActionsWorkflowRoutes(
m,
reqRepoWriter(unit.TypeActions),
Copy link
Member

Choose a reason for hiding this comment

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

The second parameter seems unnecessary.

@lunny lunny modified the milestones: 1.23.0, 1.24.0 Nov 6, 2024
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/api This PR adds API routes or modifies them modifies/go Pull requests that update Go code size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants