Skip to content

Commit 6b0a07f

Browse files
committed
Merge branch 'trunk' of https://github.com/cli/cli into feature/action-headers
2 parents 97f8074 + 6aedba3 commit 6b0a07f

File tree

99 files changed

+3274
-3271
lines changed

Some content is hidden

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

99 files changed

+3274
-3271
lines changed

.github/CONTRIBUTING.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ Run the new binary as:
3636

3737
Run tests with: `go test ./...`
3838

39+
See [project layout documentation](../project-layout.md) for information on where to find specific source files.
40+
3941
## Submitting a pull request
4042

4143
1. Create a new branch: `git checkout -b my-branch-name`

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<!--
2+
Thank you for contributing to GitHub CLI!
3+
To reference an open issue, please write this in your description: `Fixes #NUMBER`
4+
-->

.github/PULL_REQUEST_TEMPLATE/bug_fix.md

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

.github/workflows/releases.yml

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ jobs:
8080
popd
8181
- name: Run reprepro
8282
env:
83-
RELEASES: "cosmic eoan disco groovy focal stable oldstable testing unstable buster bullseye stretch jessie bionic trusty precise xenial"
83+
RELEASES: "cosmic eoan disco groovy focal stable oldstable testing unstable buster bullseye stretch jessie bionic trusty precise xenial hirsute impish kali-rolling"
8484
run: |
8585
mkdir -p upload
8686
for release in $RELEASES; do
@@ -133,9 +133,11 @@ jobs:
133133
- name: Build MSI
134134
id: buildmsi
135135
shell: bash
136+
env:
137+
ZIP_FILE: ${{ steps.download_exe.outputs.zip }}
136138
run: |
137139
mkdir -p build
138-
msi="$(basename "${{ steps.download_exe.outputs.zip }}" ".zip").msi"
140+
msi="$(basename "$ZIP_FILE" ".zip").msi"
139141
printf "::set-output name=msi::%s\n" "$msi"
140142
go-msi make --msi "$PWD/$msi" --out "$PWD/build" --version "${GITHUB_REF#refs/tags/}"
141143
- name: Obtain signing cert
@@ -145,14 +147,24 @@ jobs:
145147
run: .\script\setup-windows-certificate.ps1
146148
- name: Sign MSI
147149
env:
150+
CERT_FILE: ${{ steps.obtain_cert.outputs.cert-file }}
151+
EXE_FILE: ${{ steps.buildmsi.outputs.msi }}
148152
GITHUB_CERT_PASSWORD: ${{ secrets.GITHUB_CERT_PASSWORD }}
149-
run: |
150-
.\script\sign.ps1 -Certificate "${{ steps.obtain_cert.outputs.cert-file }}" `
151-
-Executable "${{ steps.buildmsi.outputs.msi }}"
153+
run: .\script\sign.ps1 -Certificate $env:CERT_FILE -Executable $env:EXE_FILE
152154
- name: Upload MSI
153155
shell: bash
154-
run: hub release edit "${GITHUB_REF#refs/tags/}" -m "" --draft=false -a "${{ steps.buildmsi.outputs.msi }}"
156+
run: |
157+
tag_name="${GITHUB_REF#refs/tags/}"
158+
hub release edit "$tag_name" -m "" -a "$MSI_FILE"
159+
release_url="$(gh api repos/:owner/:repo/releases -q ".[]|select(.tag_name==\"${tag_name}\")|.url")"
160+
publish_args=( -F draft=false )
161+
if [[ $GITHUB_REF != *-* ]]; then
162+
publish_args+=( -f discussion_category_name="$DISCUSSION_CATEGORY" )
163+
fi
164+
gh api -X PATCH "$release_url" "${publish_args[@]}"
155165
env:
166+
MSI_FILE: ${{ steps.buildmsi.outputs.msi }}
167+
DISCUSSION_CATEGORY: General
156168
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
157169
- name: Bump homebrew-core formula
158170
uses: mislav/bump-homebrew-formula-action@v1

api/export_pr.go

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,11 @@ import (
66
)
77

88
func (issue *Issue) ExportData(fields []string) *map[string]interface{} {
9+
v := reflect.ValueOf(issue).Elem()
910
data := map[string]interface{}{}
1011

1112
for _, f := range fields {
1213
switch f {
13-
case "milestone":
14-
if issue.Milestone.Title != "" {
15-
data[f] = &issue.Milestone
16-
} else {
17-
data[f] = nil
18-
}
1914
case "comments":
2015
data[f] = issue.Comments.Nodes
2116
case "assignees":
@@ -25,7 +20,6 @@ func (issue *Issue) ExportData(fields []string) *map[string]interface{} {
2520
case "projectCards":
2621
data[f] = issue.ProjectCards.Nodes
2722
default:
28-
v := reflect.ValueOf(issue).Elem()
2923
sf := fieldByName(v, f)
3024
data[f] = sf.Interface()
3125
}
@@ -35,24 +29,42 @@ func (issue *Issue) ExportData(fields []string) *map[string]interface{} {
3529
}
3630

3731
func (pr *PullRequest) ExportData(fields []string) *map[string]interface{} {
32+
v := reflect.ValueOf(pr).Elem()
3833
data := map[string]interface{}{}
3934

4035
for _, f := range fields {
4136
switch f {
4237
case "headRepository":
43-
data[f] = map[string]string{"name": pr.HeadRepository.Name}
44-
case "milestone":
45-
if pr.Milestone.Title != "" {
46-
data[f] = &pr.Milestone
47-
} else {
48-
data[f] = nil
49-
}
38+
data[f] = pr.HeadRepository
5039
case "statusCheckRollup":
51-
if n := pr.Commits.Nodes; len(n) > 0 {
40+
if n := pr.StatusCheckRollup.Nodes; len(n) > 0 {
5241
data[f] = n[0].Commit.StatusCheckRollup.Contexts.Nodes
5342
} else {
5443
data[f] = nil
5544
}
45+
case "commits":
46+
commits := make([]interface{}, 0, len(pr.Commits.Nodes))
47+
for _, c := range pr.Commits.Nodes {
48+
commit := c.Commit
49+
authors := make([]interface{}, 0, len(commit.Authors.Nodes))
50+
for _, author := range commit.Authors.Nodes {
51+
authors = append(authors, map[string]interface{}{
52+
"name": author.Name,
53+
"email": author.Email,
54+
"id": author.User.ID,
55+
"login": author.User.Login,
56+
})
57+
}
58+
commits = append(commits, map[string]interface{}{
59+
"oid": commit.OID,
60+
"messageHeadline": commit.MessageHeadline,
61+
"messageBody": commit.MessageBody,
62+
"committedDate": commit.CommittedDate,
63+
"authoredDate": commit.AuthoredDate,
64+
"authors": authors,
65+
})
66+
}
67+
data[f] = commits
5668
case "comments":
5769
data[f] = pr.Comments.Nodes
5870
case "assignees":
@@ -75,7 +87,6 @@ func (pr *PullRequest) ExportData(fields []string) *map[string]interface{} {
7587
}
7688
data[f] = &requests
7789
default:
78-
v := reflect.ValueOf(pr).Elem()
7990
sf := fieldByName(v, f)
8091
data[f] = sf.Interface()
8192
}
@@ -84,22 +95,6 @@ func (pr *PullRequest) ExportData(fields []string) *map[string]interface{} {
8495
return &data
8596
}
8697

87-
func ExportIssues(issues []Issue, fields []string) *[]interface{} {
88-
data := make([]interface{}, len(issues))
89-
for i := range issues {
90-
data[i] = issues[i].ExportData(fields)
91-
}
92-
return &data
93-
}
94-
95-
func ExportPRs(prs []PullRequest, fields []string) *[]interface{} {
96-
data := make([]interface{}, len(prs))
97-
for i := range prs {
98-
data[i] = prs[i].ExportData(fields)
99-
}
100-
return &data
101-
}
102-
10398
func fieldByName(v reflect.Value, field string) reflect.Value {
10499
return v.FieldByNameFunc(func(s string) bool {
105100
return strings.EqualFold(field, s)

api/export_pr_test.go

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ func TestIssue_ExportData(t *testing.T) {
4040
outputJSON: heredoc.Doc(`
4141
{
4242
"milestone": {
43-
"title": "The next big thing"
43+
"number": 0,
44+
"title": "The next big thing",
45+
"description": "",
46+
"dueOn": null
4447
},
4548
"number": 2345
4649
}
@@ -90,31 +93,6 @@ func TestIssue_ExportData(t *testing.T) {
9093
}
9194
}
9295

93-
func TestExportIssues(t *testing.T) {
94-
issues := []Issue{
95-
{Milestone: Milestone{Title: "hi"}},
96-
{},
97-
}
98-
exported := ExportIssues(issues, []string{"milestone"})
99-
100-
buf := bytes.Buffer{}
101-
enc := json.NewEncoder(&buf)
102-
enc.SetIndent("", "\t")
103-
require.NoError(t, enc.Encode(exported))
104-
assert.Equal(t, heredoc.Doc(`
105-
[
106-
{
107-
"milestone": {
108-
"title": "hi"
109-
}
110-
},
111-
{
112-
"milestone": null
113-
}
114-
]
115-
`), buf.String())
116-
}
117-
11896
func TestPullRequest_ExportData(t *testing.T) {
11997
tests := []struct {
12098
name string
@@ -144,7 +122,10 @@ func TestPullRequest_ExportData(t *testing.T) {
144122
outputJSON: heredoc.Doc(`
145123
{
146124
"milestone": {
147-
"title": "The next big thing"
125+
"number": 0,
126+
"title": "The next big thing",
127+
"description": "",
128+
"dueOn": null
148129
},
149130
"number": 2345
150131
}
@@ -154,7 +135,7 @@ func TestPullRequest_ExportData(t *testing.T) {
154135
name: "status checks",
155136
fields: []string{"statusCheckRollup"},
156137
inputJSON: heredoc.Doc(`
157-
{ "commits": { "nodes": [
138+
{ "statusCheckRollup": { "nodes": [
158139
{ "commit": { "statusCheckRollup": { "contexts": { "nodes": [
159140
{
160141
"__typename": "CheckRun",

api/export_repo.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package api
2+
3+
import (
4+
"reflect"
5+
)
6+
7+
func (repo *Repository) ExportData(fields []string) *map[string]interface{} {
8+
v := reflect.ValueOf(repo).Elem()
9+
data := map[string]interface{}{}
10+
11+
for _, f := range fields {
12+
switch f {
13+
case "parent":
14+
data[f] = miniRepoExport(repo.Parent)
15+
case "templateRepository":
16+
data[f] = miniRepoExport(repo.TemplateRepository)
17+
case "languages":
18+
data[f] = repo.Languages.Edges
19+
case "labels":
20+
data[f] = repo.Labels.Nodes
21+
case "assignableUsers":
22+
data[f] = repo.AssignableUsers.Nodes
23+
case "mentionableUsers":
24+
data[f] = repo.MentionableUsers.Nodes
25+
case "milestones":
26+
data[f] = repo.Milestones.Nodes
27+
case "projects":
28+
data[f] = repo.Projects.Nodes
29+
case "repositoryTopics":
30+
var topics []RepositoryTopic
31+
for _, n := range repo.RepositoryTopics.Nodes {
32+
topics = append(topics, n.Topic)
33+
}
34+
data[f] = topics
35+
default:
36+
sf := fieldByName(v, f)
37+
data[f] = sf.Interface()
38+
}
39+
}
40+
41+
return &data
42+
}
43+
44+
func miniRepoExport(r *Repository) map[string]interface{} {
45+
if r == nil {
46+
return nil
47+
}
48+
return map[string]interface{}{
49+
"id": r.ID,
50+
"name": r.Name,
51+
"owner": r.Owner,
52+
}
53+
}

api/pull_request_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
func TestPullRequest_ChecksStatus(t *testing.T) {
1111
pr := PullRequest{}
1212
payload := `
13-
{ "commits": { "nodes": [{ "commit": {
13+
{ "statusCheckRollup": { "nodes": [{ "commit": {
1414
"statusCheckRollup": {
1515
"contexts": {
1616
"nodes": [

0 commit comments

Comments
 (0)