Skip to content

Commit c5a2def

Browse files
committed
Merge branch 'trunk' into gh-attestation-tuf-client-retry
2 parents fcd23dc + ee281fd commit c5a2def

63 files changed

Lines changed: 2463 additions & 464 deletions

Some content is hidden

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

.github/workflows/deployment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ jobs:
309309
rpmsign --addsign dist/*.rpm
310310
- name: Attest release artifacts
311311
if: inputs.environment == 'production'
312-
uses: actions/attest-build-provenance@bd77c077858b8d561b7a36cbe48ef4cc642ca39d # v2.2.2
312+
uses: actions/attest-build-provenance@db473fddc028af60658334401dc6fa3ffd8669fd # v2.3.0
313313
with:
314314
subject-path: "dist/gh_*"
315315
- name: Run createrepo
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
skip 'it creates a fork owned by the user running the test'
2+
skip 'this never worked, but could be fixed if we fixed show-refs'
3+
4+
# Setup environment variables used for testscript
5+
env REPO=${SCRIPT_NAME}-${RANDOM_STRING}
6+
env FORK=${REPO}-fork
7+
8+
# Use gh as a credential helper
9+
exec gh auth setup-git
10+
11+
# Get the current username for the fork owner
12+
exec gh api user --jq .login
13+
stdout2env USER
14+
15+
# Create a repository to act as upstream with a file so it has a default branch
16+
exec gh repo create ${ORG}/${REPO} --add-readme --private
17+
18+
# Defer repo cleanup of upstream
19+
defer gh repo delete --yes ${ORG}/${REPO}
20+
21+
# Create a user fork of repository. This will be owned by USER.
22+
exec gh repo fork ${ORG}/${REPO} --fork-name ${FORK}
23+
sleep 5
24+
25+
# Defer repo cleanup of fork
26+
defer gh repo delete --yes ${USER}/${FORK}
27+
28+
# Retrieve fork repository information
29+
exec gh repo view ${USER}/${FORK} --json id --jq '.id'
30+
stdout2env FORK_ID
31+
32+
# Clone the repo
33+
exec gh repo clone ${USER}/${FORK}
34+
cd ${FORK}
35+
36+
# Configure push.default so that it should use the merge ref
37+
exec git config push.default upstream
38+
39+
# But prepare a branch that doesn't have a tracking merge ref
40+
exec git checkout -b feature-branch
41+
exec git commit --allow-empty -m 'Empty Commit'
42+
exec git push origin feature-branch
43+
44+
# Create the PR
45+
exec gh pr create --title 'Feature Title' --body 'Feature Body'
46+
stdout https://${GH_HOST}/${ORG}/${REPO}/pull/1
47+
48+
# Assert that the PR was created with the correct head repository and refs
49+
exec gh pr view --json headRefName,headRepository,baseRefName,isCrossRepository
50+
stdout {"baseRefName":"main","headRefName":"feature-branch","headRepository":{"id":"${FORK_ID}","name":"${FORK}"},"isCrossRepository":true}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
skip 'it creates a fork owned by the user running the test'
2+
3+
# Setup environment variables used for testscript
4+
env REPO=${SCRIPT_NAME}-${RANDOM_STRING}
5+
6+
# Use gh as a credential helper
7+
exec gh auth setup-git
8+
9+
# Get the current username for the fork owner
10+
exec gh api user --jq .login
11+
stdout2env USER
12+
13+
# Create a repository to act as upstream with a file so it has a default branch
14+
exec gh repo create ${ORG}/${REPO} --add-readme --private
15+
16+
# Defer repo cleanup of upstream
17+
defer gh repo delete --yes ${ORG}/${REPO}
18+
19+
# Clone the repo
20+
exec gh repo clone ${ORG}/${REPO}
21+
cd ${REPO}
22+
23+
# Configure push.default so that it should use the merge ref
24+
exec git config push.default upstream
25+
26+
# But prepare a branch that doesn't have a tracking merge ref
27+
exec git checkout -b feature-branch
28+
exec git commit --allow-empty -m 'Empty Commit'
29+
exec git push origin feature-branch
30+
31+
# Create the PR
32+
exec gh pr create --title 'Feature Title' --body 'Feature Body'
33+
stdout https://${GH_HOST}/${ORG}/${REPO}/pull/1

acceptance/testdata/repo/repo-set-default.txtar

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ defer gh repo delete --yes $ORG/$SCRIPT_NAME-$RANDOM_STRING
77
# Ensure that no default is set
88
cd $SCRIPT_NAME-$RANDOM_STRING
99
exec gh repo set-default --view
10-
stderr 'no default repository has been set; use `gh repo set-default` to select one'
10+
stderr 'No default remote repository has been set. To learn more about the default repository, run: gh repo set-default --help'
1111

1212
# Set the default
1313
exec gh repo set-default $ORG/$SCRIPT_NAME-$RANDOM_STRING

api/export_pr.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,24 @@ func (issue *Issue) ExportData(fields []string) map[string]interface{} {
2828
})
2929
}
3030
data[f] = items
31+
case "closedByPullRequestsReferences":
32+
items := make([]map[string]interface{}, 0, len(issue.ClosedByPullRequestsReferences.Nodes))
33+
for _, n := range issue.ClosedByPullRequestsReferences.Nodes {
34+
items = append(items, map[string]interface{}{
35+
"id": n.ID,
36+
"number": n.Number,
37+
"url": n.URL,
38+
"repository": map[string]interface{}{
39+
"id": n.Repository.ID,
40+
"name": n.Repository.Name,
41+
"owner": map[string]interface{}{
42+
"id": n.Repository.Owner.ID,
43+
"login": n.Repository.Owner.Login,
44+
},
45+
},
46+
})
47+
}
48+
data[f] = items
3149
default:
3250
sf := fieldByName(v, f)
3351
data[f] = sf.Interface()
@@ -139,6 +157,24 @@ func (pr *PullRequest) ExportData(fields []string) map[string]interface{} {
139157
}
140158
}
141159
data[f] = &requests
160+
case "closingIssuesReferences":
161+
items := make([]map[string]interface{}, 0, len(pr.ClosingIssuesReferences.Nodes))
162+
for _, n := range pr.ClosingIssuesReferences.Nodes {
163+
items = append(items, map[string]interface{}{
164+
"id": n.ID,
165+
"number": n.Number,
166+
"url": n.URL,
167+
"repository": map[string]interface{}{
168+
"id": n.Repository.ID,
169+
"name": n.Repository.Name,
170+
"owner": map[string]interface{}{
171+
"id": n.Repository.Owner.ID,
172+
"login": n.Repository.Owner.Login,
173+
},
174+
},
175+
})
176+
}
177+
data[f] = items
142178
default:
143179
sf := fieldByName(v, f)
144180
data[f] = sf.Interface()

api/export_pr_test.go

Lines changed: 136 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,70 @@ func TestIssue_ExportData(t *testing.T) {
107107
}
108108
`),
109109
},
110+
{
111+
name: "linked pull requests",
112+
fields: []string{"closedByPullRequestsReferences"},
113+
inputJSON: heredoc.Doc(`
114+
{ "closedByPullRequestsReferences": { "nodes": [
115+
{
116+
"id": "I_123",
117+
"number": 123,
118+
"url": "https://github.com/cli/cli/pull/123",
119+
"repository": {
120+
"id": "R_123",
121+
"name": "cli",
122+
"owner": {
123+
"id": "O_123",
124+
"login": "cli"
125+
}
126+
}
127+
},
128+
{
129+
"id": "I_456",
130+
"number": 456,
131+
"url": "https://github.com/cli/cli/pull/456",
132+
"repository": {
133+
"id": "R_456",
134+
"name": "cli",
135+
"owner": {
136+
"id": "O_456",
137+
"login": "cli"
138+
}
139+
}
140+
}
141+
] } }
142+
`),
143+
outputJSON: heredoc.Doc(`
144+
{ "closedByPullRequestsReferences": [
145+
{
146+
"id": "I_123",
147+
"number": 123,
148+
"repository": {
149+
"id": "R_123",
150+
"name": "cli",
151+
"owner": {
152+
"id": "O_123",
153+
"login": "cli"
154+
}
155+
},
156+
"url": "https://github.com/cli/cli/pull/123"
157+
},
158+
{
159+
"id": "I_456",
160+
"number": 456,
161+
"repository": {
162+
"id": "R_456",
163+
"name": "cli",
164+
"owner": {
165+
"id": "O_456",
166+
"login": "cli"
167+
}
168+
},
169+
"url": "https://github.com/cli/cli/pull/456"
170+
}
171+
] }
172+
`),
173+
},
110174
}
111175
for _, tt := range tests {
112176
t.Run(tt.name, func(t *testing.T) {
@@ -120,7 +184,14 @@ func TestIssue_ExportData(t *testing.T) {
120184
enc := json.NewEncoder(&buf)
121185
enc.SetIndent("", "\t")
122186
require.NoError(t, enc.Encode(exported))
123-
assert.Equal(t, tt.outputJSON, buf.String())
187+
188+
var gotData interface{}
189+
dec = json.NewDecoder(&buf)
190+
require.NoError(t, dec.Decode(&gotData))
191+
var expectData interface{}
192+
require.NoError(t, json.Unmarshal([]byte(tt.outputJSON), &expectData))
193+
194+
assert.Equal(t, expectData, gotData)
124195
})
125196
}
126197
}
@@ -245,6 +316,70 @@ func TestPullRequest_ExportData(t *testing.T) {
245316
}
246317
`),
247318
},
319+
{
320+
name: "linked issues",
321+
fields: []string{"closingIssuesReferences"},
322+
inputJSON: heredoc.Doc(`
323+
{ "closingIssuesReferences": { "nodes": [
324+
{
325+
"id": "I_123",
326+
"number": 123,
327+
"url": "https://github.com/cli/cli/issues/123",
328+
"repository": {
329+
"id": "R_123",
330+
"name": "cli",
331+
"owner": {
332+
"id": "O_123",
333+
"login": "cli"
334+
}
335+
}
336+
},
337+
{
338+
"id": "I_456",
339+
"number": 456,
340+
"url": "https://github.com/cli/cli/issues/456",
341+
"repository": {
342+
"id": "R_456",
343+
"name": "cli",
344+
"owner": {
345+
"id": "O_456",
346+
"login": "cli"
347+
}
348+
}
349+
}
350+
] } }
351+
`),
352+
outputJSON: heredoc.Doc(`
353+
{ "closingIssuesReferences": [
354+
{
355+
"id": "I_123",
356+
"number": 123,
357+
"repository": {
358+
"id": "R_123",
359+
"name": "cli",
360+
"owner": {
361+
"id": "O_123",
362+
"login": "cli"
363+
}
364+
},
365+
"url": "https://github.com/cli/cli/issues/123"
366+
},
367+
{
368+
"id": "I_456",
369+
"number": 456,
370+
"repository": {
371+
"id": "R_456",
372+
"name": "cli",
373+
"owner": {
374+
"id": "O_456",
375+
"login": "cli"
376+
}
377+
},
378+
"url": "https://github.com/cli/cli/issues/456"
379+
}
380+
] }
381+
`),
382+
},
248383
}
249384
for _, tt := range tests {
250385
t.Run(tt.name, func(t *testing.T) {

api/queries_comments.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ type CommentCreateInput struct {
4444
SubjectId string
4545
}
4646

47+
type CommentDeleteInput struct {
48+
CommentId string
49+
}
50+
4751
type CommentUpdateInput struct {
4852
Body string
4953
CommentId string
@@ -99,6 +103,27 @@ func CommentUpdate(client *Client, repoHost string, params CommentUpdateInput) (
99103
return mutation.UpdateIssueComment.IssueComment.URL, nil
100104
}
101105

106+
func CommentDelete(client *Client, repoHost string, params CommentDeleteInput) error {
107+
var mutation struct {
108+
DeleteIssueComment struct {
109+
ClientMutationID string
110+
} `graphql:"deleteIssueComment(input: $input)"`
111+
}
112+
113+
variables := map[string]interface{}{
114+
"input": githubv4.DeleteIssueCommentInput{
115+
ID: githubv4.ID(params.CommentId),
116+
},
117+
}
118+
119+
err := client.Mutate(repoHost, "CommentDelete", &mutation, variables)
120+
if err != nil {
121+
return err
122+
}
123+
124+
return nil
125+
}
126+
102127
func (c Comment) Identifier() string {
103128
return c.ID
104129
}

api/queries_issue.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,28 @@ type Issue struct {
4444
Milestone *Milestone
4545
ReactionGroups ReactionGroups
4646
IsPinned bool
47+
48+
ClosedByPullRequestsReferences ClosedByPullRequestsReferences
49+
}
50+
51+
type ClosedByPullRequestsReferences struct {
52+
Nodes []struct {
53+
ID string
54+
Number int
55+
URL string
56+
Repository struct {
57+
ID string
58+
Name string
59+
Owner struct {
60+
ID string
61+
Login string
62+
}
63+
}
64+
}
65+
PageInfo struct {
66+
HasNextPage bool
67+
EndCursor string
68+
}
4769
}
4870

4971
// return values for Issue.Typename

0 commit comments

Comments
 (0)