Skip to content

Commit d2d0b47

Browse files
committed
Merge branch 'master' into reviewers-in-pr-view
2 parents 1ce09ff + d908320 commit d2d0b47

File tree

22 files changed

+410
-130
lines changed

22 files changed

+410
-130
lines changed

.github/workflows/releases.yml

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ jobs:
1717
go-version: 1.13
1818
- name: Generate changelog
1919
run: |
20+
echo ::set-env name=GORELEASER_CURRENT_TAG::${GITHUB_REF#refs/tags/}
2021
git fetch --unshallow
2122
script/changelog | tee CHANGELOG.md
2223
- name: Run GoReleaser
@@ -26,25 +27,35 @@ jobs:
2627
args: release --release-notes=CHANGELOG.md
2728
env:
2829
GITHUB_TOKEN: ${{secrets.UPLOAD_GITHUB_TOKEN}}
29-
- name: move cards
30-
if: "!contains(github.ref, '-')"
30+
- name: Bump homebrew-core formula
31+
uses: mislav/bump-homebrew-formula-action@v1
32+
if: "!contains(github.ref, '-')" # skip prereleases
33+
with:
34+
formula-name: gh
35+
env:
36+
COMMITTER_TOKEN: ${{ secrets.UPLOAD_GITHUB_TOKEN }}
37+
- name: Checkout documentation site
38+
if: "!contains(github.ref, '-')" # skip prereleases
39+
uses: actions/checkout@v2
40+
with:
41+
repository: github/cli.github.com
42+
path: site
43+
fetch-depth: 0
44+
token: ${{secrets.SITE_GITHUB_TOKEN}}
45+
- name: Publish documentation site
46+
if: "!contains(github.ref, '-')" # skip prereleases
47+
run: make site-publish
48+
- name: Move project cards
49+
if: "!contains(github.ref, '-')" # skip prereleases
3150
env:
3251
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
3352
PENDING_COLUMN: 8189733
3453
DONE_COLUMN: 7110130
35-
shell: bash
3654
run: |
3755
curl -fsSL https://github.com/github/hub/raw/master/script/get | bash -s 2.14.1
3856
api() { bin/hub api -H 'accept: application/vnd.github.inertia-preview+json' "$@"; }
3957
cards=$(api projects/columns/$PENDING_COLUMN/cards | jq ".[].id")
4058
for card in $cards; do api projects/columns/cards/$card/moves --field position=top --field column_id=$DONE_COLUMN; done
41-
- name: Bump homebrew-core formula
42-
uses: mislav/bump-homebrew-formula-action@v1
43-
if: "!contains(github.ref, '-')" # skip prereleases
44-
with:
45-
formula-name: gh
46-
env:
47-
COMMITTER_TOKEN: ${{ secrets.UPLOAD_GITHUB_TOKEN }}
4859
msi:
4960
needs: goreleaser
5061
runs-on: windows-latest

Makefile

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,15 @@ site-docs: site
3232
for f in site/manual/gh*.md; do sed -i.bak -e '/^### SEE ALSO/,$$d' "$$f"; done
3333
rm -f site/manual/*.bak
3434
git -C site add 'manual/gh*.md'
35-
git -C site commit -m 'update help docs'
35+
git -C site commit -m 'update help docs' || true
3636
.PHONY: site-docs
37+
38+
site-publish: site-docs
39+
ifndef GITHUB_REF
40+
$(error GITHUB_REF is not set)
41+
endif
42+
sed -i.bak -E 's/(assign version = )".+"/\1"$(GITHUB_REF:refs/tags/v%=%)"/' site/index.html
43+
rm -f site/index.html.bak
44+
git -C site commit -m '$(GITHUB_REF:refs/tags/v%=%)' index.html
45+
git -C site push
46+
.PHONY: site-publish

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ the terminal next to where you are already working with `git` and your code.
77

88
## Availability
99

10-
While in beta, GitHub CLI is available for repos hosted on GitHub.com only. It does not currently support repositories hosted on GitHub Enterprise Server or other hosting providers. We are planning support for GitHub Enterprise Server after GitHub CLI is out of beta (likely toward the end of 2020), and we want to ensure that the API endpoints we use are more widely available for GHES versions that most GitHub customers are on.
10+
While in beta, GitHub CLI is available for repos hosted on GitHub.com only. It does not currently support repositories hosted on GitHub Enterprise Server or other hosting providers. We are planning support for GitHub Enterprise Server after GitHub CLI is out of beta (likely toward the end of 2020), and we want to ensure that the API endpoints we use are more widely available for GHES versions that most GitHub customers are on.
1111

1212
## We need your feedback
1313

@@ -22,6 +22,7 @@ And if you spot bugs or have features that you'd really like to see in `gh`, ple
2222
- `gh pr [status, list, view, checkout, create]`
2323
- `gh issue [status, list, view, create]`
2424
- `gh repo [view, create, clone, fork]`
25+
- `gh config [get, set]`
2526
- `gh help`
2627

2728
## Documentation

api/client.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ func AddHeader(name, value string) ClientOption {
3737
}
3838
}
3939

40+
// AddHeaderFunc is an AddHeader that gets the string value from a function
41+
func AddHeaderFunc(name string, value func() string) ClientOption {
42+
return func(tr http.RoundTripper) http.RoundTripper {
43+
return &funcTripper{roundTrip: func(req *http.Request) (*http.Response, error) {
44+
req.Header.Add(name, value())
45+
return tr.RoundTrip(req)
46+
}}
47+
}
48+
}
49+
4050
// VerboseLog enables request/response logging within a RoundTripper
4151
func VerboseLog(out io.Writer, logTraffic bool, colorize bool) ClientOption {
4252
logger := &httpretty.Logger{
@@ -63,6 +73,40 @@ func ReplaceTripper(tr http.RoundTripper) ClientOption {
6373
}
6474
}
6575

76+
var issuedScopesWarning bool
77+
78+
// CheckScopes checks whether an OAuth scope is present in a response
79+
func CheckScopes(wantedScope string, cb func(string) error) ClientOption {
80+
return func(tr http.RoundTripper) http.RoundTripper {
81+
return &funcTripper{roundTrip: func(req *http.Request) (*http.Response, error) {
82+
res, err := tr.RoundTrip(req)
83+
if err != nil || res.StatusCode > 299 || issuedScopesWarning {
84+
return res, err
85+
}
86+
87+
appID := res.Header.Get("X-Oauth-Client-Id")
88+
hasScopes := strings.Split(res.Header.Get("X-Oauth-Scopes"), ",")
89+
90+
hasWanted := false
91+
for _, s := range hasScopes {
92+
if wantedScope == strings.TrimSpace(s) {
93+
hasWanted = true
94+
break
95+
}
96+
}
97+
98+
if !hasWanted {
99+
if err := cb(appID); err != nil {
100+
return res, err
101+
}
102+
issuedScopesWarning = true
103+
}
104+
105+
return res, nil
106+
}}
107+
}
108+
}
109+
66110
type funcTripper struct {
67111
roundTrip func(*http.Request) (*http.Response, error)
68112
}

auth/oauth.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"net/http"
1212
"net/url"
1313
"os"
14+
"strings"
1415

1516
"github.com/cli/cli/pkg/browser"
1617
)
@@ -29,6 +30,7 @@ type OAuthFlow struct {
2930
Hostname string
3031
ClientID string
3132
ClientSecret string
33+
Scopes []string
3234
WriteSuccessHTML func(io.Writer)
3335
VerboseStream io.Writer
3436
}
@@ -45,11 +47,15 @@ func (oa *OAuthFlow) ObtainAccessToken() (accessToken string, err error) {
4547
}
4648
port := listener.Addr().(*net.TCPAddr).Port
4749

50+
scopes := "repo"
51+
if oa.Scopes != nil {
52+
scopes = strings.Join(oa.Scopes, " ")
53+
}
54+
4855
q := url.Values{}
4956
q.Set("client_id", oa.ClientID)
5057
q.Set("redirect_uri", fmt.Sprintf("http://127.0.0.1:%d/callback", port))
51-
// TODO: make scopes configurable
52-
q.Set("scope", "repo")
58+
q.Set("scope", scopes)
5359
q.Set("state", state)
5460

5561
startURL := fmt.Sprintf("https://%s/login/oauth/authorize?%s", oa.Hostname, q.Encode())

command/issue.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,11 @@ func issueProjectList(issue api.Issue) string {
504504

505505
projectNames := make([]string, 0, len(issue.ProjectCards.Nodes))
506506
for _, project := range issue.ProjectCards.Nodes {
507-
projectNames = append(projectNames, fmt.Sprintf("%s (%s)", project.Project.Name, project.Column.Name))
507+
colName := project.Column.Name
508+
if colName == "" {
509+
colName = "Awaiting triage"
510+
}
511+
projectNames = append(projectNames, fmt.Sprintf("%s (%s)", project.Project.Name, colName))
508512
}
509513

510514
list := strings.Join(projectNames, ", ")

command/issue_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ func TestIssueView_Preview(t *testing.T) {
312312
`Open • marseilles opened about 292 years ago • 9 comments`,
313313
`Assignees: marseilles, monaco\n`,
314314
`Labels: one, two, three, four, five\n`,
315-
`Projects: Project 1 \(column A\), Project 2 \(column B\), Project 3 \(column C\)\n`,
315+
`Projects: Project 1 \(column A\), Project 2 \(column B\), Project 3 \(column C\), Project 4 \(Awaiting triage\)\n`,
316316
`Milestone: uluru\n`,
317317
`bold story`,
318318
`View this issue on GitHub: https://github.com/OWNER/REPO/issues/123`,

command/pr.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,11 @@ func prProjectList(pr api.PullRequest) string {
531531

532532
projectNames := make([]string, 0, len(pr.ProjectCards.Nodes))
533533
for _, project := range pr.ProjectCards.Nodes {
534-
projectNames = append(projectNames, fmt.Sprintf("%s (%s)", project.Project.Name, project.Column.Name))
534+
colName := project.Column.Name
535+
if colName == "" {
536+
colName = "Awaiting triage"
537+
}
538+
projectNames = append(projectNames, fmt.Sprintf("%s (%s)", project.Project.Name, colName))
535539
}
536540

537541
list := strings.Join(projectNames, ", ")

command/pr_checkout.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func prCheckout(cmd *cobra.Command, args []string) error {
4747

4848
baseRemote, _ := remotes.FindByRepo(baseRepo.RepoOwner(), baseRepo.RepoName())
4949
// baseRemoteSpec is a repository URL or a remote name to be used in git fetch
50-
baseURLOrName := fmt.Sprintf("https://github.com/%s.git", ghrepo.FullName(baseRepo))
50+
baseURLOrName := formatRemoteURL(cmd, ghrepo.FullName(baseRepo))
5151
if baseRemote != nil {
5252
baseURLOrName = baseRemote.Name
5353
}
@@ -97,7 +97,7 @@ func prCheckout(cmd *cobra.Command, args []string) error {
9797
remote := baseURLOrName
9898
mergeRef := ref
9999
if pr.MaintainerCanModify {
100-
remote = fmt.Sprintf("https://github.com/%s/%s.git", pr.HeadRepositoryOwner.Login, pr.HeadRepository.Name)
100+
remote = formatRemoteURL(cmd, fmt.Sprintf("%s/%s", pr.HeadRepositoryOwner.Login, pr.HeadRepository.Name))
101101
mergeRef = fmt.Sprintf("refs/heads/%s", pr.HeadRefName)
102102
}
103103
if mc, err := git.Config(fmt.Sprintf("branch.%s.merge", newBranchName)); err != nil || mc == "" {

command/pr_create.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,8 @@ func prCreate(cmd *cobra.Command, _ []string) error {
250250
// In either case, we want to add the head repo as a new git remote so we
251251
// can push to it.
252252
if headRemote == nil {
253-
// TODO: support non-HTTPS git remote URLs
254-
headRepoURL := fmt.Sprintf("https://github.com/%s.git", ghrepo.FullName(headRepo))
253+
headRepoURL := formatRemoteURL(cmd, ghrepo.FullName(headRepo))
254+
255255
// TODO: prevent clashes with another remote of a same name
256256
gitRemote, err := git.AddRemote("fork", headRepoURL)
257257
if err != nil {

0 commit comments

Comments
 (0)