Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ inputs:
description: Close the advisory of an issue a maintainer closed as a duplicate, credit its reporter on the original report and tell them on the closed advisory. Needs `issues-repository`.
default: "false"
comment:
description: Post the triage as a comment on the advisory. Off by default, every triage then only reaches `project`, which must be set.
description: Post the triage as a comment on the advisory, and with `issues-repository` the link to each issue tamis creates. Off by default, every triage then only reaches `project`, which must be set.
default: "false"
references:
description: Whitespace-separated local git references, including each supported release branch. The first is analysed, and the cited code is located on it. All must have been fetched.
Expand Down
2 changes: 1 addition & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
| `engine` | `claude` | `claude` for Claude Code and the Anthropic API, `openai` for Codex and the OpenAI API. |
| `model` | `claude-opus-5-5` or `gpt-5.5` | Model of the reader, the duplicate search and the exact confirmation. `gpt-6.1-sol` with a Codex access token. |
| `daybreak` | `false` | Turns on OpenAI's Daybreak cyber access program in Codex. Needs `engine: openai` and an API key whose organisation OpenAI approved for it. |
| `comment` | `false` | Post the triage as a comment on the advisory. Off, every triage only reaches `project`, which must then be set, and the board records the failed attempts in `Attempts`. |
| `comment` | `false` | Post the triage as a comment on the advisory, and with `issues-repository` a comment linking each advisory to the issue tamis creates for it. Off, every triage only reaches `project`, which must then be set, and the board records the failed attempts in `Attempts`. |
| `project` | | Private organisation project kept in sync with the advisories, as `org/number`. See [the project board](setup.md#5-project-board). |
| `issues-repository` | | Private repository the board items are created in as issues, so duplicates become sub-issues of their original report. Drafts when unset. See [the project board](setup.md#5-project-board). |
| `issues-token` | | Installation token for `issues-repository` only, with the "Issues" and organisation "Projects" permissions in read and write. Required with `issues-repository`. |
Expand Down
18 changes: 17 additions & 1 deletion internal/board/board.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ type Board struct {
ig Issues
// unlisted holds the issues of a previous run that never reached the board, by lowercase GHSA identifier.
unlisted map[string]github.Issue
// created holds the link of each issue this run created, by GHSA identifier.
created map[string]string
}

// issueMarker names the advisory of an issue, so an issue created by a run that failed to put it on the board is
Expand Down Expand Up @@ -233,7 +235,7 @@ func Open(ctx context.Context, gh GitHub, ig Issues, project, issues, advisories
return nil, errors.New("the issues repository must be private")
}
}
b := &Board{gh: gh, org: org, number: number, ids: map[string]int64{}, options: map[string]map[string]string{}, items: map[string]*item{}, issues: issues, ig: ig}
b := &Board{gh: gh, org: org, number: number, ids: map[string]int64{}, options: map[string]map[string]string{}, items: map[string]*item{}, issues: issues, ig: ig, created: map[string]string{}}
fields, err := gh.ListProjectFields(ctx, org, number)
if err != nil {
return nil, err
Expand Down Expand Up @@ -435,6 +437,7 @@ func (b *Board) put(ctx context.Context, a github.Advisory, priority string, t *
return err
}
b.unlisted[key] = issue
b.created[a.GHSAID] = issue.HTMLURL
}
added, err := b.ig.AddProjectIssue(ctx, b.org, b.number, issue.ID)
if err != nil {
Expand Down Expand Up @@ -693,6 +696,19 @@ func (b *Board) CloseDuplicates(ctx context.Context, gh Advisories, repo string,
return errors.Join(errs...)
}

// LinkIssues tells each advisory whose issue this run created where the maintainers track it. An issue found
// again from a failed run is left out, since that run may have linked it already.
func (b *Board) LinkIssues(ctx context.Context, gh Advisories, repo string) error {
var errs []error
for ghsa, link := range b.created {
if err := gh.PostComment(ctx, repo, ghsa, fmt.Sprintf("Tracked in %s.", link)); err != nil {
errs = append(errs, fmt.Errorf("linking the issue of %s: %w", ghsa, err))
}
}

return errors.Join(errs...)
}

// closeDuplicate comments before closing, since the next run leaves a closed advisory alone. A close that failed
// after its comment finds that comment on the next run instead of posting it again. It returns the original and
// the login credited on it, empty when the original credits nobody for it.
Expand Down
35 changes: 35 additions & 0 deletions internal/board/board_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1157,3 +1157,38 @@ func TestSyncKeepsTheIssueOfAClosedDuplicateClosedAsSuch(t *testing.T) {
require.Equal(t, "closed", p.Value(p.Find("GHSA-dup"), "State"))
require.Equal(t, "not_planned", p.IssueOf(p.Find("GHSA-orig")).StateReason)
}

func TestLinkIssuesCommentsOnTheAdvisoriesOfTheIssuesItCreated(t *testing.T) {
p := boardtest.New()
p.Issues[1] = &boardtest.Issue{ID: 1001, Repo: "acme/private-issues", Title: "s", Body: "<!-- tamis-issue GHSA-aaaa-bbbb-cccc -->", State: "open"}
b, err := Open(t.Context(), p, p, "php/16", "acme/private-issues", "php/php-src")
require.NoError(t, err)
require.NoError(t, b.Put(t.Context(), github.Advisory{GHSAID: "GHSA-new", Summary: "s", State: "triage"}, ToTriage, &Triage{}, ""))
require.NoError(t, b.Put(t.Context(), github.Advisory{GHSAID: "GHSA-aaaa-bbbb-cccc", Summary: "s", State: "triage"}, ToTriage, &Triage{}, ""))
f := &advisories{comments: map[string][]string{}}

require.NoError(t, b.LinkIssues(t.Context(), f, "php/php-src"))

require.Equal(t, map[string][]string{"GHSA-new": {"Tracked in https://github.com/acme/private-issues/issues/2."}}, f.comments, "an issue found again from a failed run was linked")
}

func TestLinkIssuesReportsAFailedComment(t *testing.T) {
p := boardtest.New()
b, err := Open(t.Context(), p, p, "php/16", "acme/private-issues", "php/php-src")
require.NoError(t, err)
require.NoError(t, b.Put(t.Context(), github.Advisory{GHSAID: "GHSA-new", Summary: "s", State: "triage"}, ToTriage, &Triage{}, ""))

require.ErrorContains(t, b.LinkIssues(t.Context(), &advisories{postErr: errors.New("HTTP 502")}, "php/php-src"), "linking the issue of GHSA-new: HTTP 502")
}

func TestLinkIssuesLeavesDraftsAlone(t *testing.T) {
p := boardtest.New()
b, err := Open(t.Context(), p, p, "php/16", "", "php/php-src")
require.NoError(t, err)
require.NoError(t, b.Put(t.Context(), github.Advisory{GHSAID: "GHSA-new", Summary: "s", State: "triage"}, ToTriage, &Triage{}, ""))
f := &advisories{comments: map[string][]string{}}

require.NoError(t, b.LinkIssues(t.Context(), f, "php/php-src"))

require.Empty(t, f.comments)
}
2 changes: 1 addition & 1 deletion internal/board/boardtest/boardtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ func (p *Project) CreateIssue(_ context.Context, repo, title, body string) (gith
n := len(p.Issues) + 1
p.Issues[n] = &Issue{ID: int64(1000 + n), Repo: repo, Title: title, Body: body, State: "open"}

return github.Issue{ID: int64(1000 + n), Number: n}, nil
return github.Issue{ID: int64(1000 + n), Number: n, HTMLURL: fmt.Sprintf("https://github.com/%s/issues/%d", repo, n)}, nil
}

func (p *Project) UpdateIssue(_ context.Context, repo string, number int, fields map[string]string) error {
Expand Down
6 changes: 6 additions & 0 deletions internal/triage/triage.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,12 @@ func Run(ctx context.Context, cfg Config, gh GitHub, reader Reader, eng engine.E
triaged++
}

if b != nil && !cfg.NoComment {
if err := b.LinkIssues(ctx, gh, cfg.Repo); err != nil {
log.Error("linking the issues on their advisories failed", "reason", describe(err))
boardErr = errors.Join(boardErr, errors.New("linking the issues: "+describe(err)))
}
}
if b != nil {
if err := b.Sync(ctx, all); err != nil {
log.Error("syncing the project board failed", "reason", describe(err))
Expand Down
11 changes: 10 additions & 1 deletion internal/triage/triage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1558,7 +1558,16 @@ func TestRunPutsTheTriageInAPrivateIssue(t *testing.T) {
require.NotNil(t, issue, "the board triage is not an issue")
require.Equal(t, "acme/private-issues", issue.Repo)
require.Contains(t, issue.Body, report.Marker, "the issue misses the triage")
require.Empty(t, gh.posted, "the board triage posted a comment")
require.Equal(t, map[string]string{"GHSA-done": "Tracked in https://github.com/acme/private-issues/issues/1."}, gh.posted, "the advisory misses the link to its issue, or got the triage")
}

func TestRunLinksNoIssueWithoutComments(t *testing.T) {
gh, eng := newFixture(), &fakeEngine{}

require.NoError(t, run(t, Config{Advisory: "GHSA-done", Project: "php/16", IssuesRepository: "acme/private-issues", NoComment: true}, gh, eng))

require.NotNil(t, gh.IssueOf(gh.Find("GHSA-done")))
require.Empty(t, gh.posted)
}

func TestRunClosesTheReportOfAnIssueClosedAsADuplicateOnlyWhenAsked(t *testing.T) {
Expand Down
Loading