Skip to content

Commit d0f168f

Browse files
committed
Merge remote-tracking branch 'origin/master' into issue-pr-create-metadata
2 parents b59407d + 3000847 commit d0f168f

25 files changed

+1199
-307
lines changed

.github/workflows/codeql.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Code Scanning
2+
3+
on:
4+
push:
5+
schedule:
6+
- cron: "0 0 * * 0"
7+
8+
jobs:
9+
CodeQL-Build:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Check out code
14+
uses: actions/checkout@v2
15+
16+
- name: Initialize CodeQL
17+
uses: github/codeql-action/init@v1
18+
with:
19+
languages: go
20+
21+
- name: Perform CodeQL Analysis
22+
uses: github/codeql-action/analyze@v1

api/client_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"io/ioutil"
66
"reflect"
77
"testing"
8+
9+
"github.com/cli/cli/pkg/httpmock"
810
)
911

1012
func eq(t *testing.T, got interface{}, expected interface{}) {
@@ -15,7 +17,7 @@ func eq(t *testing.T, got interface{}, expected interface{}) {
1517
}
1618

1719
func TestGraphQL(t *testing.T) {
18-
http := &FakeHTTP{}
20+
http := &httpmock.Registry{}
1921
client := NewClient(
2022
ReplaceTripper(http),
2123
AddHeader("Authorization", "token OTOKEN"),
@@ -40,7 +42,7 @@ func TestGraphQL(t *testing.T) {
4042
}
4143

4244
func TestGraphQLError(t *testing.T) {
43-
http := &FakeHTTP{}
45+
http := &httpmock.Registry{}
4446
client := NewClient(ReplaceTripper(http))
4547

4648
response := struct{}{}
@@ -52,7 +54,7 @@ func TestGraphQLError(t *testing.T) {
5254
}
5355

5456
func TestRESTGetDelete(t *testing.T) {
55-
http := &FakeHTTP{}
57+
http := &httpmock.Registry{}
5658

5759
client := NewClient(
5860
ReplaceTripper(http),

api/fake_http.go

Lines changed: 0 additions & 101 deletions
This file was deleted.

api/queries_issue_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ import (
77
"testing"
88

99
"github.com/cli/cli/internal/ghrepo"
10+
"github.com/cli/cli/pkg/httpmock"
1011
)
1112

1213
func TestIssueList(t *testing.T) {
13-
http := &FakeHTTP{}
14+
http := &httpmock.Registry{}
1415
client := NewClient(ReplaceTripper(http))
1516

1617
http.StubResponse(200, bytes.NewBufferString(`

api/queries_pr.go

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,29 @@
11
package api
22

33
import (
4+
"context"
45
"fmt"
56
"strings"
67
"time"
78

9+
"github.com/shurcooL/githubv4"
10+
811
"github.com/cli/cli/internal/ghrepo"
912
)
1013

14+
type PullRequestReviewState int
15+
16+
const (
17+
ReviewApprove PullRequestReviewState = iota
18+
ReviewRequestChanges
19+
ReviewComment
20+
)
21+
22+
type PullRequestReviewInput struct {
23+
Body string
24+
State PullRequestReviewState
25+
}
26+
1127
type PullRequestsPayload struct {
1228
ViewerCreated PullRequestAndTotalCount
1329
ReviewRequested PullRequestAndTotalCount
@@ -24,6 +40,7 @@ type PullRequest struct {
2440
Number int
2541
Title string
2642
State string
43+
Closed bool
2744
URL string
2845
BaseRefName string
2946
HeadRefName string
@@ -345,10 +362,12 @@ func PullRequestByNumber(client *Client, repo ghrepo.Interface, number int) (*Pu
345362
query($owner: String!, $repo: String!, $pr_number: Int!) {
346363
repository(owner: $owner, name: $repo) {
347364
pullRequest(number: $pr_number) {
365+
id
348366
url
349367
number
350368
title
351369
state
370+
closed
352371
body
353372
author {
354373
login
@@ -451,6 +470,7 @@ func PullRequestForBranch(client *Client, repo ghrepo.Interface, baseBranch, hea
451470
repository(owner: $owner, name: $repo) {
452471
pullRequests(headRefName: $headRefName, states: OPEN, first: 30) {
453472
nodes {
473+
id
454474
number
455475
title
456476
state
@@ -654,6 +674,34 @@ func isBlank(v interface{}) bool {
654674
}
655675
}
656676

677+
func AddReview(client *Client, pr *PullRequest, input *PullRequestReviewInput) error {
678+
var mutation struct {
679+
AddPullRequestReview struct {
680+
ClientMutationID string
681+
} `graphql:"addPullRequestReview(input:$input)"`
682+
}
683+
684+
state := githubv4.PullRequestReviewEventComment
685+
switch input.State {
686+
case ReviewApprove:
687+
state = githubv4.PullRequestReviewEventApprove
688+
case ReviewRequestChanges:
689+
state = githubv4.PullRequestReviewEventRequestChanges
690+
}
691+
692+
body := githubv4.String(input.Body)
693+
694+
gqlInput := githubv4.AddPullRequestReviewInput{
695+
PullRequestID: pr.ID,
696+
Event: &state,
697+
Body: &body,
698+
}
699+
700+
v4 := githubv4.NewClient(client.http)
701+
702+
return v4.Mutate(context.Background(), &mutation, gqlInput, nil)
703+
}
704+
657705
func PullRequestList(client *Client, vars map[string]interface{}, limit int) (*PullRequestAndTotalCount, error) {
658706
type prBlock struct {
659707
Edges []struct {
@@ -822,6 +870,44 @@ loop:
822870
return &res, nil
823871
}
824872

873+
func PullRequestClose(client *Client, repo ghrepo.Interface, pr *PullRequest) error {
874+
var mutation struct {
875+
ClosePullRequest struct {
876+
PullRequest struct {
877+
ID githubv4.ID
878+
}
879+
} `graphql:"closePullRequest(input: $input)"`
880+
}
881+
882+
input := githubv4.ClosePullRequestInput{
883+
PullRequestID: pr.ID,
884+
}
885+
886+
v4 := githubv4.NewClient(client.http)
887+
err := v4.Mutate(context.Background(), &mutation, input, nil)
888+
889+
return err
890+
}
891+
892+
func PullRequestReopen(client *Client, repo ghrepo.Interface, pr *PullRequest) error {
893+
var mutation struct {
894+
ReopenPullRequest struct {
895+
PullRequest struct {
896+
ID githubv4.ID
897+
}
898+
} `graphql:"reopenPullRequest(input: $input)"`
899+
}
900+
901+
input := githubv4.ReopenPullRequestInput{
902+
PullRequestID: pr.ID,
903+
}
904+
905+
v4 := githubv4.NewClient(client.http)
906+
err := v4.Mutate(context.Background(), &mutation, input, nil)
907+
908+
return err
909+
}
910+
825911
func min(a, b int) int {
826912
if a < b {
827913
return a

api/queries_repo_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ import (
55
"encoding/json"
66
"io/ioutil"
77
"testing"
8+
9+
"github.com/cli/cli/pkg/httpmock"
810
)
911

1012
func Test_RepoCreate(t *testing.T) {
11-
http := &FakeHTTP{}
13+
http := &httpmock.Registry{}
1214
client := NewClient(ReplaceTripper(http))
1315

1416
http.StubResponse(200, bytes.NewBufferString(`{}`))

command/completion_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
)
77

88
func TestCompletion_bash(t *testing.T) {
9-
output, err := RunCommand(completionCmd, `completion`)
9+
output, err := RunCommand(`completion`)
1010
if err != nil {
1111
t.Fatal(err)
1212
}
@@ -17,7 +17,7 @@ func TestCompletion_bash(t *testing.T) {
1717
}
1818

1919
func TestCompletion_zsh(t *testing.T) {
20-
output, err := RunCommand(completionCmd, `completion -s zsh`)
20+
output, err := RunCommand(`completion -s zsh`)
2121
if err != nil {
2222
t.Fatal(err)
2323
}
@@ -28,7 +28,7 @@ func TestCompletion_zsh(t *testing.T) {
2828
}
2929

3030
func TestCompletion_fish(t *testing.T) {
31-
output, err := RunCommand(completionCmd, `completion -s fish`)
31+
output, err := RunCommand(`completion -s fish`)
3232
if err != nil {
3333
t.Fatal(err)
3434
}
@@ -39,7 +39,7 @@ func TestCompletion_fish(t *testing.T) {
3939
}
4040

4141
func TestCompletion_powerShell(t *testing.T) {
42-
output, err := RunCommand(completionCmd, `completion -s powershell`)
42+
output, err := RunCommand(`completion -s powershell`)
4343
if err != nil {
4444
t.Fatal(err)
4545
}
@@ -50,7 +50,7 @@ func TestCompletion_powerShell(t *testing.T) {
5050
}
5151

5252
func TestCompletion_unsupported(t *testing.T) {
53-
_, err := RunCommand(completionCmd, `completion -s csh`)
53+
_, err := RunCommand(`completion -s csh`)
5454
if err == nil || err.Error() != `unsupported shell type "csh"` {
5555
t.Fatal(err)
5656
}

0 commit comments

Comments
 (0)