-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
[Fix] Trigger 'unlabeled' event when label is Deleted from PR #34316
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
Open
Sumit189
wants to merge
9
commits into
go-gitea:main
Choose a base branch
from
Sumit189:label_delete_event_fix
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
15e707c
Enhance label event handling in matchIssuesEvent function and add tes…
Sumit189 76d0a98
Merge branch 'main' into label_delete_event_fix
Sumit189 cecac31
Enhance matchIssuesEvent function to support multiple label actions a…
Sumit189 e0ad6b0
Merge branch 'label_delete_event_fix' of https://github.com/Sumit189/…
Sumit189 6664116
fix assert order
Sumit189 56314f6
Update modules/actions/workflows.go
Sumit189 84b684e
Add support for removed labels in issue and pull request notifications
Sumit189 8b6f3ba
Merge branch 'main' into label_delete_event_fix
Sumit189 6aa8ba3
Merge branch 'main' into label_delete_event_fix
Sumit189 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,12 @@ type actionsNotifier struct { | |
notify_service.NullNotifier | ||
} | ||
|
||
type contextKey string | ||
|
||
const ( | ||
removedLabelsKey contextKey = "GiteaRemovedLabels" | ||
) | ||
|
||
var _ notify_service.Notifier = &actionsNotifier{} | ||
|
||
// NewNotifier create a new actionsNotifier notifier | ||
|
@@ -189,7 +195,7 @@ func (n *actionsNotifier) IssueChangeMilestone(ctx context.Context, doer *user_m | |
} | ||
|
||
func (n *actionsNotifier) IssueChangeLabels(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, | ||
_, _ []*issues_model.Label, | ||
addedLabels, removedLabels []*issues_model.Label, | ||
) { | ||
ctx = withMethod(ctx, "IssueChangeLabels") | ||
|
||
|
@@ -198,6 +204,22 @@ func (n *actionsNotifier) IssueChangeLabels(ctx context.Context, doer *user_mode | |
hookEvent = webhook_module.HookEventPullRequestLabel | ||
} | ||
|
||
// Track removedLabels for the webhook payload | ||
var removedAPILabels []*api.Label | ||
if len(removedLabels) > 0 { | ||
if err := issue.LoadRepo(ctx); err != nil { | ||
log.Error("LoadRepo: %v", err) | ||
return | ||
} | ||
|
||
removedAPILabels = make([]*api.Label, 0, len(removedLabels)) | ||
for _, label := range removedLabels { | ||
removedAPILabels = append(removedAPILabels, convert.ToLabel(label, issue.Repo, doer)) | ||
} | ||
|
||
ctx = context.WithValue(ctx, removedLabelsKey, removedAPILabels) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's better to change the notify function signature directly to make it explicated. |
||
} | ||
|
||
notifyIssueChange(ctx, doer, issue, hookEvent, api.HookIssueLabelUpdated) | ||
} | ||
|
||
|
@@ -213,34 +235,50 @@ func notifyIssueChange(ctx context.Context, doer *user_model.User, issue *issues | |
return | ||
} | ||
|
||
// Get removed labels from context if present | ||
var removedAPILabels []*api.Label | ||
if removedLabelsValue := ctx.Value(removedLabelsKey); removedLabelsValue != nil { | ||
if labels, ok := removedLabelsValue.([]*api.Label); ok { | ||
removedAPILabels = labels | ||
} | ||
} | ||
|
||
if issue.IsPull { | ||
if err = issue.LoadPullRequest(ctx); err != nil { | ||
log.Error("loadPullRequest: %v", err) | ||
return | ||
} | ||
|
||
payload := &api.PullRequestPayload{ | ||
Action: action, | ||
Index: issue.Index, | ||
PullRequest: convert.ToAPIPullRequest(ctx, issue.PullRequest, nil), | ||
Repository: convert.ToRepo(ctx, issue.Repo, access_model.Permission{AccessMode: perm_model.AccessModeNone}), | ||
Sender: convert.ToUser(ctx, doer, nil), | ||
RemovedLabels: removedAPILabels, | ||
} | ||
|
||
newNotifyInputFromIssue(issue, event). | ||
WithDoer(doer). | ||
WithPayload(&api.PullRequestPayload{ | ||
Action: action, | ||
Index: issue.Index, | ||
PullRequest: convert.ToAPIPullRequest(ctx, issue.PullRequest, nil), | ||
Repository: convert.ToRepo(ctx, issue.Repo, access_model.Permission{AccessMode: perm_model.AccessModeNone}), | ||
Sender: convert.ToUser(ctx, doer, nil), | ||
}). | ||
WithPayload(payload). | ||
WithPullRequest(issue.PullRequest). | ||
Notify(ctx) | ||
return | ||
} | ||
|
||
permission, _ := access_model.GetUserRepoPermission(ctx, issue.Repo, issue.Poster) | ||
payload := &api.IssuePayload{ | ||
Action: action, | ||
Index: issue.Index, | ||
Issue: convert.ToAPIIssue(ctx, doer, issue), | ||
Repository: convert.ToRepo(ctx, issue.Repo, permission), | ||
Sender: convert.ToUser(ctx, doer, nil), | ||
RemovedLabels: removedAPILabels, | ||
} | ||
|
||
newNotifyInputFromIssue(issue, event). | ||
WithDoer(doer). | ||
WithPayload(&api.IssuePayload{ | ||
Action: action, | ||
Index: issue.Index, | ||
Issue: convert.ToAPIIssue(ctx, doer, issue), | ||
Repository: convert.ToRepo(ctx, issue.Repo, permission), | ||
Sender: convert.ToUser(ctx, doer, nil), | ||
}). | ||
WithPayload(payload). | ||
Notify(ctx) | ||
} | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.