Skip to content

Commit de4e37e

Browse files
author
nate smith
committed
Merge remote-tracking branch 'origin/trunk' into feat/gist-edit
2 parents ab668e8 + 7ef3abe commit de4e37e

File tree

231 files changed

+9531
-3768
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

231 files changed

+9531
-3768
lines changed

.github/workflows/go.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ jobs:
1717
- name: Check out code
1818
uses: actions/checkout@v2
1919

20+
- name: Cache Go modules
21+
uses: actions/cache@v2
22+
with:
23+
path: ~/go
24+
key: ${{ runner.os }}-build-${{ hashFiles('go.mod') }}
25+
restore-keys: |
26+
${{ runner.os }}-build-
27+
${{ runner.os }}-
28+
2029
- name: Download dependencies
2130
run: go mod download
2231

.github/workflows/issueauto.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Issue Automation
2+
on:
3+
issues:
4+
types: [opened]
5+
jobs:
6+
issue-auto:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: label incoming issue
10+
env:
11+
GH_REPO: ${{ github.repository }}
12+
GH_TOKEN: ${{ secrets.AUTOMATION_TOKEN }}
13+
ISSUENUM: ${{ github.event.issue.number }}
14+
ISSUEAUTHOR: ${{ github.event.issue.user.login }}
15+
run: |
16+
if ! gh api orgs/cli/public_members/$ISSUEAUTHOR --silent 2>/dev/null
17+
then
18+
gh issue edit $ISSUENUM --add-label "needs-triage"
19+
fi

.github/workflows/prauto.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ jobs:
4545
4646
if [ "$PR_AUTHOR_TYPE" = "Bot" ] || gh api orgs/cli/public_members/$PRAUTHOR --silent 2>/dev/null
4747
then
48+
if [ "$PR_AUTHOR_TYPE" != "Bot" ]
49+
then
50+
gh pr edit $PRNUM --add-assignee $PRAUTHOR
51+
fi
4852
if ! errtext="$(addToBoard 2>&1)"
4953
then
5054
cat <<<"$errtext" >&2
@@ -56,6 +60,8 @@ jobs:
5660
exit 0
5761
fi
5862
63+
gh pr edit $PRNUM --add-label "external"
64+
5965
if [ "$PRHEAD" = "cli:trunk" ]
6066
then
6167
closePR

.github/workflows/releases.yml

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ jobs:
2525
-q .body > CHANGELOG.md
2626
env:
2727
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
28+
- name: Install osslsigncode
29+
run: sudo apt-get install -y osslsigncode
2830
- name: Run GoReleaser
2931
uses: goreleaser/goreleaser-action@v2
3032
with:
@@ -33,6 +35,8 @@ jobs:
3335
env:
3436
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
3537
GORELEASER_CURRENT_TAG: ${{steps.changelog.outputs.tag-name}}
38+
GITHUB_CERT_PASSWORD: ${{secrets.GITHUB_CERT_PASSWORD}}
39+
DESKTOP_CERT_TOKEN: ${{secrets.DESKTOP_CERT_TOKEN}}
3640
- name: Checkout documentation site
3741
uses: actions/checkout@v2
3842
with:
@@ -61,7 +65,6 @@ jobs:
6165
api-write --silent projects/columns/cards/$card/moves -f position=top -F column_id=$DONE_COLUMN
6266
done
6367
echo "moved ${#cards[@]} cards to the Done column"
64-
6568
- name: Install packaging dependencies
6669
run: sudo apt-get install -y rpm reprepro
6770
- name: Set up GPG
@@ -129,23 +132,19 @@ jobs:
129132
unzip -o *.zip && rm -v *.zip
130133
env:
131134
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
132-
- name: Install go-msi
133-
run: choco install -y "go-msi"
134135
- name: Prepare PATH
135-
shell: bash
136-
run: |
137-
echo "$WIX\\bin" >> $GITHUB_PATH
138-
echo "C:\\Program Files\\go-msi" >> $GITHUB_PATH
136+
id: setupmsbuild
137+
uses: microsoft/setup-msbuild@v1.0.3
139138
- name: Build MSI
140139
id: buildmsi
141140
shell: bash
142141
env:
143142
ZIP_FILE: ${{ steps.download_exe.outputs.zip }}
143+
MSBUILD_PATH: ${{ steps.setupmsbuild.outputs.msbuildPath }}
144144
run: |
145-
mkdir -p build
146-
msi="$(basename "$ZIP_FILE" ".zip").msi"
147-
printf "::set-output name=msi::%s\n" "$msi"
148-
go-msi make --msi "$PWD/$msi" --out "$PWD/build" --version "${GITHUB_REF#refs/tags/}"
145+
name="$(basename "$ZIP_FILE" ".zip")"
146+
version="$(echo -e ${GITHUB_REF#refs/tags/v} | sed s/-.*$//)"
147+
"${MSBUILD_PATH}\MSBuild.exe" ./build/windows/gh.wixproj -p:SourceDir="$PWD" -p:OutputPath="$PWD" -p:OutputName="$name" -p:ProductVersion="$version"
149148
- name: Obtain signing cert
150149
id: obtain_cert
151150
env:

.goreleaser.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ release:
88
before:
99
hooks:
1010
- go mod tidy
11-
- make manpages
11+
- make manpages GH_VERSION={{.Version}}
12+
- ./script/prepare-windows-cert.sh '{{ if index .Env "GITHUB_CERT_PASSWORD" }}{{ .Env.GITHUB_CERT_PASSWORD}}{{ end }}' '{{ if index .Env "DESKTOP_CERT_TOKEN" }}{{ .Env.DESKTOP_CERT_TOKEN}}{{ end }}'
1213

1314
builds:
1415
- <<: &build_defaults
@@ -32,6 +33,9 @@ builds:
3233
id: windows
3334
goos: [windows]
3435
goarch: [386, amd64]
36+
hooks:
37+
post:
38+
- ./script/sign-windows-executable.sh '{{ .Path }}'
3539

3640
archives:
3741
- id: nix

CODEOWNERS

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
* @cli/code-reviewers
22

3-
pkg/cmd/codespace/* @cli/codespaces
4-
pkg/liveshare/* @cli/codespaces
5-
internal/codespaces/* @cli/codespaces
3+
pkg/cmd/codespace/ @cli/codespaces
4+
pkg/liveshare/ @cli/codespaces
5+
internal/codespaces/ @cli/codespaces

api/client.go

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import (
1212
"strings"
1313

1414
"github.com/cli/cli/v2/internal/ghinstance"
15+
graphql "github.com/cli/shurcooL-graphql"
1516
"github.com/henvic/httpretty"
16-
"github.com/shurcooL/graphql"
1717
)
1818

1919
// ClientOption represents an argument to NewClient
@@ -98,6 +98,22 @@ func ReplaceTripper(tr http.RoundTripper) ClientOption {
9898
}
9999
}
100100

101+
// ExtractHeader extracts a named header from any response received by this client and, if non-blank, saves
102+
// it to dest.
103+
func ExtractHeader(name string, dest *string) ClientOption {
104+
return func(tr http.RoundTripper) http.RoundTripper {
105+
return &funcTripper{roundTrip: func(req *http.Request) (*http.Response, error) {
106+
res, err := tr.RoundTrip(req)
107+
if err == nil {
108+
if value := res.Header.Get(name); value != "" {
109+
*dest = value
110+
}
111+
}
112+
return res, err
113+
}}
114+
}
115+
}
116+
101117
type funcTripper struct {
102118
roundTrip func(*http.Request) (*http.Response, error)
103119
}
@@ -124,7 +140,18 @@ type graphQLResponse struct {
124140
type GraphQLError struct {
125141
Type string
126142
Message string
127-
// Path []interface // mixed strings and numbers
143+
Path []interface{} // mixed strings and numbers
144+
}
145+
146+
func (ge GraphQLError) PathString() string {
147+
var res strings.Builder
148+
for i, v := range ge.Path {
149+
if i > 0 {
150+
res.WriteRune('.')
151+
}
152+
fmt.Fprintf(&res, "%v", v)
153+
}
154+
return res.String()
128155
}
129156

130157
// GraphQLErrorResponse contains errors returned in a GraphQL response
@@ -135,9 +162,31 @@ type GraphQLErrorResponse struct {
135162
func (gr GraphQLErrorResponse) Error() string {
136163
errorMessages := make([]string, 0, len(gr.Errors))
137164
for _, e := range gr.Errors {
138-
errorMessages = append(errorMessages, e.Message)
165+
msg := e.Message
166+
if p := e.PathString(); p != "" {
167+
msg = fmt.Sprintf("%s (%s)", msg, p)
168+
}
169+
errorMessages = append(errorMessages, msg)
170+
}
171+
return fmt.Sprintf("GraphQL: %s", strings.Join(errorMessages, ", "))
172+
}
173+
174+
// Match checks if this error is only about a specific type on a specific path. If the path argument ends
175+
// with a ".", it will match all its subpaths as well.
176+
func (gr GraphQLErrorResponse) Match(expectType, expectPath string) bool {
177+
for _, e := range gr.Errors {
178+
if e.Type != expectType || !matchPath(e.PathString(), expectPath) {
179+
return false
180+
}
181+
}
182+
return true
183+
}
184+
185+
func matchPath(p, expect string) bool {
186+
if strings.HasSuffix(expect, ".") {
187+
return strings.HasPrefix(p, expect) || p == strings.TrimSuffix(expect, ".")
139188
}
140-
return fmt.Sprintf("GraphQL error: %s", strings.Join(errorMessages, "\n"))
189+
return p == expect
141190
}
142191

143192
// HTTPError is an error returned by a failed API call
@@ -173,7 +222,7 @@ func (err HTTPError) ScopesSuggestion() string {
173222
// ScopesSuggestion is an error messaging utility that prints the suggestion to request additional OAuth
174223
// scopes in case a server response indicates that there are missing scopes.
175224
func ScopesSuggestion(resp *http.Response) string {
176-
if resp.StatusCode < 400 || resp.StatusCode > 499 {
225+
if resp.StatusCode < 400 || resp.StatusCode > 499 || resp.StatusCode == 422 {
177226
return ""
178227
}
179228

@@ -221,7 +270,8 @@ func EndpointNeedsScopes(resp *http.Response, s string) *http.Response {
221270
return resp
222271
}
223272

224-
// GraphQL performs a GraphQL request and parses the response
273+
// GraphQL performs a GraphQL request and parses the response. If there are errors in the response,
274+
// *GraphQLErrorResponse will be returned, but the data will also be parsed into the receiver.
225275
func (c Client) GraphQL(hostname string, query string, variables map[string]interface{}, data interface{}) error {
226276
reqBody, err := json.Marshal(map[string]interface{}{"query": query, "variables": variables})
227277
if err != nil {

api/client_test.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,23 @@ func TestGraphQLError(t *testing.T) {
5050
httpmock.GraphQL(""),
5151
httpmock.StringResponse(`
5252
{ "errors": [
53-
{"message":"OH NO"},
54-
{"message":"this is fine"}
53+
{
54+
"type": "NOT_FOUND",
55+
"message": "OH NO",
56+
"path": ["repository", "issue"]
57+
},
58+
{
59+
"type": "ACTUALLY_ITS_FINE",
60+
"message": "this is fine",
61+
"path": ["repository", "issues", 0, "comments"]
62+
}
5563
]
5664
}
5765
`),
5866
)
5967

6068
err := client.GraphQL("github.com", "", nil, &response)
61-
if err == nil || err.Error() != "GraphQL error: OH NO\nthis is fine" {
69+
if err == nil || err.Error() != "GraphQL: OH NO (repository.issue), this is fine (repository.issues.0.comments)" {
6270
t.Fatalf("got %q", err.Error())
6371
}
6472
}
@@ -200,6 +208,11 @@ func TestHTTPError_ScopesSuggestion(t *testing.T) {
200208
resp: makeResponse(404, "https://api.github.com/gists", "", "gist, delete_repo"),
201209
want: ``,
202210
},
211+
{
212+
name: "http code is 422",
213+
resp: makeResponse(422, "https://api.github.com/gists", "", "gist"),
214+
want: "",
215+
},
203216
}
204217
for _, tt := range tests {
205218
t.Run(tt.name, func(t *testing.T) {

api/export_pr.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ func (pr *PullRequest) ExportData(fields []string) map[string]interface{} {
7575
data[f] = pr.ProjectCards.Nodes
7676
case "reviews":
7777
data[f] = pr.Reviews.Nodes
78+
case "latestReviews":
79+
data[f] = pr.LatestReviews.Nodes
7880
case "files":
7981
data[f] = pr.Files.Nodes
8082
case "reviewRequests":

api/queries_comments.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import (
44
"context"
55
"time"
66

7+
graphql "github.com/cli/shurcooL-graphql"
78
"github.com/shurcooL/githubv4"
8-
"github.com/shurcooL/graphql"
99
)
1010

1111
type Comments struct {

0 commit comments

Comments
 (0)