Skip to content

feat(labeler): add /assign and /unassign support - #764

Open
amanbn8 wants to merge 1 commit into
cncf:mainfrom
amanbn8:labeler-assign
Open

amanbn8 wants to merge 1 commit into
cncf:mainfrom
amanbn8:labeler-assign

Conversation

@amanbn8

@amanbn8 amanbn8 commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #109

What

Adds /assign and /unassign slash-command support to utilities/labeler via two new action kinds, assign and unassign, usable from match rules:

- name: assign
  kind: match
  spec:
    command: "/assign"
  actions:
  - kind: assign

- name: unassign
  kind: match
  spec:
    command: "/unassign"
  actions:
  - kind: unassign
Comment Effect
/assign assigns the comment author
/assign @alice bob assigns alice and bob
/unassign @alice removes alice

How

  • GitHubClient gains AddAssignees, RemoveAssignees and IsAssignee (all exist in go-github v55; no new dependencies).
  • LabelRequest gains an optional CommentAuthor. It is wired through as an optional trailing comment_author CLI argument and an optional comment_author input on .github/actions/labeler-action (pass ${{ github.event.comment.user.login }}). Existing callers that omit it keep working; only bare /assign / /unassign need it.
  • Logins are normalized: leading @ stripped, case-insensitive de-dupe. Already-assigned users are skipped on assign, not-assigned users on unassign. Users who are not assignable in the repo (per IsAssignee) are skipped with a log line rather than failing the whole run, so one bad login does not block the rest.
  • Match-rule commands must now be the first whitespace-delimited token of a line, so /assign no longer also fires on /assignee. Leading whitespace is still tolerated (strings.Fields). This matches the direction of Update labeler #640.
  • README documents the new actions and CLI argument.

Testing

cd utilities/labeler
gofmt -l .        # only the pre-existing comprehensive_test.go
go vet ./...
go test -v        # all pass, incl. 11 new tests in assign_test.go
.github/scripts/check-go-version.sh   # All Go versions match 1.27.1

New tests cover explicit users, bare self-assign, no-author no-op, skipping already-assigned/duplicate/unassignable users, IsAssignee API error, unassign explicit/self/not-assigned, and that /assignee does not trigger /assign.

Not tested against a live repository; the GitHub calls are the straightforward go-github wrappers.

Notes

The mock GetIssue now reflects the mock's assignee state. Kept the change additive to limit conflicts with #640; the processMatchRule token check is the one overlapping hunk.

Add two new action kinds, `assign` and `unassign`, usable from `match`
rules so a comment like `/assign @alice bob` adds assignees and
`/unassign @alice` removes them. With no arguments the comment author is
the target, so a bare `/assign` self-assigns (Prow semantics).

- Extend GitHubClient with AddAssignees, RemoveAssignees and IsAssignee.
- Add optional CommentAuthor to LabelRequest, an optional trailing
  `comment_author` CLI argument, and a matching optional `comment_author`
  input on .github/actions/labeler-action (backwards compatible).
- Logins are normalized (leading `@` stripped, case-insensitive dedupe).
  Already-assigned users are skipped; users who cannot be assigned in the
  repository are skipped with a log line rather than failing the run.
- Match-rule commands must now be the first whitespace-delimited token of
  a line, so `/assign` no longer also matches `/assignee`.
- Document the new actions in the labeler README.

Fixes cncf#109

Signed-off-by: Aman Bansal <amanbn@icloud.com>
@github-actions github-actions Bot added needs-kind Indicates an issue or PR that is missing an issue type or kind (a kind/foo label) needs-area Indicates an issue or PR missing an area label needs-priority Indicates an issue or PR missing a priority label needs-status Indicates an issue or PR missing a status label area/utilities Utilities and helper tools kind/github-actions This repository's workflows, reusable actions, and GitHub Actions tooling labels Oct 18, 2026
@github-actions

github-actions Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
To complete the pull request process, please assign idvoretskyi after the PR has been reviewed.
You can assign the PR to them by writing /assign @idvoretskyi in a comment when ready.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@github-actions github-actions Bot removed needs-kind Indicates an issue or PR that is missing an issue type or kind (a kind/foo label) needs-area Indicates an issue or PR missing an area label labels Oct 18, 2026
@ahmadqasembader
ahmadqasembader requested a balanced review from Copilot October 19, 2026 09:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Malformed targets can unexpectedly select the comment author or prevent valid assignments in the same command.

2 open issues
What changed in this PR

Adds configurable /assign and /unassign commands to the labeler, addressing #109.

Changes:

  • Adds assignee actions with login normalization and eligibility checks.
  • Passes an optional comment author through the CLI and Docker action.
  • Tightens command matching and adds documentation and tests.
File Description
utilities/​labeler/​README.md Documents assignment commands and author input.
utilities/​labeler/​main.go Accepts the optional comment-author argument.
utilities/​labeler/​labeler.go Implements assignee actions and exact-token matching.
utilities/​labeler/​labeler_test.go Extends mocks with assignee state and operations.
utilities/​labeler/​assign_test.go Tests assignment behavior and command matching.
.github/​actions/​labeler-action/​action.yml Forwards the optional comment-author input.

Review effort: Balanced

// `/assign` semantics.
func (l *Labeler) resolveAssignees(req *LabelRequest, argv []string) []string {
logins := normalizeLogins(argv)
if len(logins) == 0 && req.CommentAuthor != "" {
Comment on lines +375 to +377
ok, _, err := l.client.IsAssignee(ctx, req.Owner, req.Repo, login)
if err != nil {
return fmt.Errorf("failed to check whether %s can be assigned: %v", login, err)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/utilities Utilities and helper tools kind/github-actions This repository's workflows, reusable actions, and GitHub Actions tooling needs-priority Indicates an issue or PR missing a priority label needs-status Indicates an issue or PR missing a status label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Labeler: Add support for assign

2 participants