diff options
| author | Taras Madan <tarasmadan@google.com> | 2023-06-20 10:30:07 +0200 |
|---|---|---|
| committer | Taras Madan <tarasmadan@google.com> | 2023-06-20 15:04:32 +0200 |
| commit | 0cf1feea4ed6ec2e962a5116275c5de83e09b728 (patch) | |
| tree | 59e19769da87203fb7933b3ba2ea1ca8957a6061 | |
| parent | 09ffe269727719aad37ea8145eb57fefb0097165 (diff) | |
dashboard/app: export fix-commits as a json
| -rw-r--r-- | dashboard/app/getjson_test.go | 50 | ||||
| -rw-r--r-- | dashboard/app/public_json_api.go | 25 |
2 files changed, 73 insertions, 2 deletions
diff --git a/dashboard/app/getjson_test.go b/dashboard/app/getjson_test.go index 91ef5f75d..7f60b15ea 100644 --- a/dashboard/app/getjson_test.go +++ b/dashboard/app/getjson_test.go @@ -6,6 +6,8 @@ package main import ( "fmt" "testing" + + "github.com/google/syzkaller/dashboard/dashapi" ) func TestJSONAPIIntegration(t *testing.T) { @@ -97,3 +99,51 @@ func checkBugGroupPageJSONIs(c *Ctx, url string, expectedContent []byte) { actualContent, _ := c.client.GET(url) c.expectEQ(string(actualContent), string(expectedContent)) } + +func TestJSONAPIFixCommits(t *testing.T) { + c := NewCtx(t) + defer c.Close() + + build1 := testBuild(1) + c.client.UploadBuild(build1) + + crash1 := testCrash(build1, 1) + c.client.ReportCrash(crash1) + rep1 := c.client.pollBug() + + // Specify fixing commit for the bug. + c.client.ReportingUpdate(&dashapi.BugUpdate{ + ID: rep1.ID, + Status: dashapi.BugStatusOpen, + FixCommits: []string{"foo: fix1", "foo: fix2"}, + }) + + c.client.UploadCommits([]dashapi.Commit{ + {Hash: "hash1", Title: "foo: fix1"}, + }) + + c.client.CommitPoll() + + want := []byte(`{ + "version": 1, + "title": "title1", + "fix-commits": [ + { + "title": "foo: fix1", + "hash": "hash1" + }, + { + "title": "foo: fix2" + } + ], + "crashes": [ + { + "kernel-config": "/text?tag=KernelConfig\u0026x=a989f27ebc47e2dc", + "kernel-source-commit": "1111111111111111111111111111111111111111", + "syzkaller-git": "https://github.com/google/syzkaller/commits/syzkaller_commit1", + "syzkaller-commit": "syzkaller_commit1" + } + ] +}`) + checkBugGroupPageJSONIs(c, "/bug?extid=decf42d66dced481afc1&json=1", want) +} diff --git a/dashboard/app/public_json_api.go b/dashboard/app/public_json_api.go index 2adc1f7e7..bbf330e2f 100644 --- a/dashboard/app/public_json_api.go +++ b/dashboard/app/public_json_api.go @@ -8,13 +8,20 @@ import "encoding/json" // publicApiBugDescription is used to serve the /bug HTTP requests // and provide JSON description of the BUG. Backward compatible. type publicAPIBugDescription struct { - Version int `json:"version"` - Title string `json:"title,omitempty"` + Version int `json:"version"` + Title string `json:"title,omitempty"` + FixCommits []fixCommit `json:"fix-commits,omitempty"` // links to the discussions Discussions []string `json:"discussions,omitempty"` Crashes []publicAPICrashDescription `json:"crashes,omitempty"` } +type fixCommit struct { + Title string `json:"title"` + Link string `json:"link,omitempty"` + Hash string `json:"hash,omitempty"` +} + type publicAPICrashDescription struct { SyzReproducer string `json:"syz-reproducer,omitempty"` CReproducer string `json:"c-reproducer,omitempty"` @@ -38,6 +45,20 @@ func getExtAPIDescrForBugPage(bugPage *uiBugPage) *publicAPIBugDescription { } return []string{bugPage.Bug.ExternalLink} }(), + FixCommits: func() []fixCommit { + if len(bugPage.Bug.Commits) == 0 { + return nil + } + var res []fixCommit + for _, commit := range bugPage.Bug.Commits { + res = append(res, fixCommit{ + Title: commit.Title, + Hash: commit.Hash, + Link: commit.Link, + }) + } + return res + }(), Crashes: []publicAPICrashDescription{{ SyzReproducer: crash.ReproSyzLink, CReproducer: crash.ReproCLink, |
