Skip to content

Commit

Permalink
Fix issue for upload of pullrequest resource
Browse files Browse the repository at this point in the history
Seems the PR instance not `Unmarshal` from pr.json on the dist when uploading
  • Loading branch information
vincent-pli committed Dec 10, 2019
1 parent 203b953 commit 3220e0d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
18 changes: 18 additions & 0 deletions pkg/pullrequest/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ func FromDisk(path string) (*Resource, error) {
var err error
var manifest Manifest

pr, err := prFromDisk(path, "pr.json")
if err != nil {
return nil, err
}
r.PR = &pr

commentsPath := filepath.Join(path, "comments")
r.Comments, manifest, err = commentsFromDisk(commentsPath)
if err != nil {
Expand Down Expand Up @@ -329,6 +335,18 @@ func refFromDisk(path, name string) (scm.PullRequestBranch, error) {
return ref, nil
}

func prFromDisk(path, name string) (scm.PullRequest, error) {
b, err := ioutil.ReadFile(filepath.Join(path, name))
if err != nil {
return scm.PullRequest{}, err
}
pr := scm.PullRequest{}
if err := json.Unmarshal(b, &pr); err != nil {
return scm.PullRequest{}, err
}
return pr, nil
}

func isNotExistError(err error) bool {
return err != nil && os.IsNotExist(err)
}
12 changes: 12 additions & 0 deletions pkg/pullrequest/disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ func TestFromDiskWithoutComments(t *testing.T) {
defer os.RemoveAll(d)

// Write some refs
pr := scm.PullRequest{
Number: 123,
Sha: "0922babb0ea5c0e91a244c5ea8acea902c077281",
Ref: "refs/pull/100/head",
}
base := scm.PullRequestBranch{
Repo: scm.Repository{Name: "repo1"},
Ref: "refs/heads/branch1",
Expand All @@ -230,6 +235,7 @@ func TestFromDiskWithoutComments(t *testing.T) {
}
writeFile(filepath.Join(d, "base.json"), &base)
writeFile(filepath.Join(d, "head.json"), &head)
writeFile(filepath.Join(d, "pr.json"), &pr)

rsrc, err := FromDisk(d)
if err != nil {
Expand All @@ -254,6 +260,11 @@ func TestFromDisk(t *testing.T) {
defer os.RemoveAll(d)

// Write some refs
pr := scm.PullRequest{
Number: 123,
Sha: "0922babb0ea5c0e91a244c5ea8acea902c077281",
Ref: "refs/pull/100/head",
}
base := scm.PullRequestBranch{
Repo: scm.Repository{Name: "repo1"},
Ref: "refs/heads/branch1",
Expand All @@ -276,6 +287,7 @@ func TestFromDisk(t *testing.T) {
}
writeFile(filepath.Join(d, "base.json"), &base)
writeFile(filepath.Join(d, "head.json"), &head)
writeFile(filepath.Join(d, "pr.json"), &pr)

// Write some statuses
statuses := []scm.Status{
Expand Down

0 comments on commit 3220e0d

Please sign in to comment.