Skip to content

Commit

Permalink
Implement comment fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
felix.niederwanger@suse.com committed Apr 20, 2021
1 parent 53f8ee5 commit 85f6c86
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 1 deletion.
11 changes: 11 additions & 0 deletions comment.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package gopenqa

type Comment struct {
ID int `json:"id"`
Text string `json:"text"` // Comment text
Rendered string `json:"renderedMarkdown"` // HTML of the rendered markdown
BugRefs []string `json:"bugrefs"` // Referenced bugs
Created string `json:"created"` // bug creation date
Updated string `json:"updated"` // timestamp for update
User string `json:"userName"` // Creator
}
7 changes: 6 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@ module github.com/grisu48/gopenqa

go 1.14

require github.com/streadway/amqp v1.0.0
require (
github.com/google/go-cmp v0.5.5 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/streadway/amqp v1.0.0
gotest.tools v2.2.0+incompatible
)
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/streadway/amqp v1.0.0 h1:kuuDrUJFZL1QYL9hUNuCxNObNzB0bV/ZG5jV3RWAQgo=
github.com/streadway/amqp v1.0.0/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gotest.tools v1.4.0 h1:BjtEgfuw8Qyd+jPvQz8CfoxiO/UjFEidWinwEXZiWv0=
gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
15 changes: 15 additions & 0 deletions gopenqa.go
Original file line number Diff line number Diff line change
Expand Up @@ -832,3 +832,18 @@ func (i *Instance) PostProduct(product Product) (Product, error) {
err = json.Unmarshal(buf, &product)
return product, err
}

/* Fetch comments for a given job */
func (i *Instance) GetComments(job int) ([]Comment, error) {
ret := make([]Comment, 0)
rurl := fmt.Sprintf("%s/api/v1/jobs/%d/comments", i.URL, job)
buf, err := i.get(rurl, nil)
if i.verbose {
fmt.Fprintf(os.Stderr, "%s\n", string(buf))
}
if err != nil {
return ret, err
}
err = json.Unmarshal(buf, &ret)
return ret, err
}
32 changes: 32 additions & 0 deletions gopenqa__test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ import (
"net/http"
"os"
"testing"

"gotest.tools/assert"
)

var instance Instance

const COMMENT_TEST_JOB_ID = 5830

/* Test server http - Serves directories in test/ */
func setupTestServer() {
fs := http.FileServer(http.Dir("./test"))
Expand Down Expand Up @@ -74,3 +78,31 @@ func TestWorkers(t *testing.T) {
return
}
}

func TestComments(t *testing.T) {
comments, err := instance.GetComments(COMMENT_TEST_JOB_ID)
if err != nil {
log.Fatalf("%s", err)
return
}
if len(comments) != 4 {
log.Fatalf("Expected 4 comments, got %d", len(comments))
return
}
// Check comments for expected content
for _, comment := range comments {
assert.Equal(t, comment.User, "phoenix")
}
assert.Equal(t, comments[0].ID, 14)
assert.Equal(t, comments[1].ID, 15)
assert.Equal(t, comments[2].ID, 16)
assert.Equal(t, comments[3].ID, 17)
assert.Equal(t, comments[1].Text, "Comment 2.")
assert.Equal(t, comments[2].Text, "poo#42")
assert.Equal(t, comments[3].Text, "bsc#1337")
assert.Assert(t, len(comments[2].BugRefs) == 1)
assert.Assert(t, len(comments[3].BugRefs) == 1)
assert.Assert(t, comments[2].BugRefs[0] == "poo#42")
assert.Assert(t, comments[3].BugRefs[0] == "bsc#1337")

}
1 change: 1 addition & 0 deletions test/jobs/5830/comments
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"bugrefs":[],"created":"2021-04-20 07:41:50 +0000","id":14,"renderedMarkdown":"<p>I take this job for testing comments.<\/p>\n<h1>Update<\/h1>\n<p>I've updated the comment.<\/p>\n","text":"I take this job for testing comments.\r\n\r\n# Update\r\n\r\nI've updated the comment.","updated":"2021-04-20 07:45:26 +0000","userName":"phoenix"},{"bugrefs":[],"created":"2021-04-20 07:45:16 +0000","id":15,"renderedMarkdown":"<p>Comment 2.<\/p>\n","text":"Comment 2.","updated":"2021-04-20 07:45:16 +0000","userName":"phoenix"},{"bugrefs":["poo#42"],"created":"2021-04-20 07:45:40 +0000","id":16,"renderedMarkdown":"<p><a href=\"https:\/\/progress.opensuse.org\/issues\/91344\">poo#42<\/a><\/p>\n","text":"poo#42","updated":"2021-04-20 07:45:40 +0000","userName":"phoenix"},{"bugrefs":["bsc#1337"],"created":"2021-04-20 07:45:48 +0000","id":17,"renderedMarkdown":"<p><a href=\"https:\/\/bugzilla.suse.com\/show_bug.cgi?id=1337\">bsc#1337<\/a><\/p>\n","text":"bsc#1337","updated":"2021-04-20 07:45:48 +0000","userName":"phoenix"}]

0 comments on commit 85f6c86

Please sign in to comment.