Skip to content

Commit 0cbcf8a

Browse files
committed
Merge remote-tracking branch 'origin' into ghe-api
2 parents 8909a3e + 7512034 commit 0cbcf8a

File tree

19 files changed

+1251
-742
lines changed

19 files changed

+1251
-742
lines changed

api/queries_repo.go

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package api
33
import (
44
"bytes"
55
"context"
6-
"encoding/base64"
76
"encoding/json"
87
"errors"
98
"fmt"
@@ -407,37 +406,6 @@ func RepoCreate(client *Client, input RepoCreateInput) (*Repository, error) {
407406
return initRepoHostname(&response.CreateRepository.Repository, "github.com"), nil
408407
}
409408

410-
type RepoReadme struct {
411-
Filename string
412-
Content string
413-
}
414-
415-
func RepositoryReadme(client *Client, repo ghrepo.Interface) (*RepoReadme, error) {
416-
var response struct {
417-
Name string
418-
Content string
419-
}
420-
421-
err := client.REST(repo.RepoHost(), "GET", fmt.Sprintf("repos/%s/readme", ghrepo.FullName(repo)), nil, &response)
422-
if err != nil {
423-
var httpError HTTPError
424-
if errors.As(err, &httpError) && httpError.StatusCode == 404 {
425-
return nil, &NotFoundError{err}
426-
}
427-
return nil, err
428-
}
429-
430-
decoded, err := base64.StdEncoding.DecodeString(response.Content)
431-
if err != nil {
432-
return nil, fmt.Errorf("failed to decode readme: %w", err)
433-
}
434-
435-
return &RepoReadme{
436-
Filename: response.Name,
437-
Content: string(decoded),
438-
}, nil
439-
}
440-
441409
type RepoMetadataResult struct {
442410
AssignableUsers []RepoAssignee
443411
Labels []RepoLabel

command/issue.go

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ func issueList(cmd *cobra.Command, args []string) error {
227227
}
228228

229229
if web {
230-
issueListURL := generateRepoURL(baseRepo, "issues")
230+
issueListURL := ghrepo.GenerateRepoURL(baseRepo, "issues")
231231
openURL, err := listURLWithQuery(issueListURL, filterOptions{
232232
entity: "issue",
233233
state: state,
@@ -240,7 +240,7 @@ func issueList(cmd *cobra.Command, args []string) error {
240240
if err != nil {
241241
return err
242242
}
243-
fmt.Fprintf(cmd.ErrOrStderr(), "Opening %s in your browser.\n", displayURL(openURL))
243+
fmt.Fprintf(cmd.ErrOrStderr(), "Opening %s in your browser.\n", utils.DisplayURL(openURL))
244244
return utils.OpenInBrowser(openURL)
245245
}
246246

@@ -504,7 +504,7 @@ func issueCreate(cmd *cobra.Command, args []string) error {
504504
}
505505

506506
if isWeb, err := cmd.Flags().GetBool("web"); err == nil && isWeb {
507-
openURL := generateRepoURL(baseRepo, "issues/new")
507+
openURL := ghrepo.GenerateRepoURL(baseRepo, "issues/new")
508508
if title != "" || body != "" {
509509
milestone := ""
510510
if len(milestoneTitles) > 0 {
@@ -518,7 +518,7 @@ func issueCreate(cmd *cobra.Command, args []string) error {
518518
openURL += "/choose"
519519
}
520520
if connectedToTerminal(cmd) {
521-
cmd.Printf("Opening %s in your browser.\n", displayURL(openURL))
521+
cmd.Printf("Opening %s in your browser.\n", utils.DisplayURL(openURL))
522522
}
523523
return utils.OpenInBrowser(openURL)
524524
}
@@ -582,7 +582,7 @@ func issueCreate(cmd *cobra.Command, args []string) error {
582582
}
583583

584584
if action == PreviewAction {
585-
openURL := generateRepoURL(baseRepo, "issues/new")
585+
openURL := ghrepo.GenerateRepoURL(baseRepo, "issues/new")
586586
milestone := ""
587587
if len(milestoneTitles) > 0 {
588588
milestone = milestoneTitles[0]
@@ -592,7 +592,7 @@ func issueCreate(cmd *cobra.Command, args []string) error {
592592
return err
593593
}
594594
// TODO could exceed max url length for explorer
595-
fmt.Fprintf(cmd.ErrOrStderr(), "Opening %s in your browser.\n", displayURL(openURL))
595+
fmt.Fprintf(cmd.ErrOrStderr(), "Opening %s in your browser.\n", utils.DisplayURL(openURL))
596596
return utils.OpenInBrowser(openURL)
597597
} else if action == SubmitAction {
598598
params := map[string]interface{}{
@@ -618,14 +618,6 @@ func issueCreate(cmd *cobra.Command, args []string) error {
618618
return nil
619619
}
620620

621-
func generateRepoURL(repo ghrepo.Interface, p string, args ...interface{}) string {
622-
baseURL := fmt.Sprintf("https://%s/%s/%s", repo.RepoHost(), repo.RepoOwner(), repo.RepoName())
623-
if p != "" {
624-
return baseURL + "/" + fmt.Sprintf(p, args...)
625-
}
626-
return baseURL
627-
}
628-
629621
func addMetadataToIssueParams(client *api.Client, baseRepo ghrepo.Interface, params map[string]interface{}, tb *issueMetadataState) error {
630622
if !tb.HasMetadata() {
631623
return nil
@@ -844,11 +836,3 @@ func issueReopen(cmd *cobra.Command, args []string) error {
844836

845837
return nil
846838
}
847-
848-
func displayURL(urlStr string) string {
849-
u, err := url.Parse(urlStr)
850-
if err != nil {
851-
return urlStr
852-
}
853-
return u.Hostname() + u.Path
854-
}

command/pr.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ func prList(cmd *cobra.Command, args []string) error {
235235
}
236236

237237
if web {
238-
prListURL := generateRepoURL(baseRepo, "pulls")
238+
prListURL := ghrepo.GenerateRepoURL(baseRepo, "pulls")
239239
openURL, err := listURLWithQuery(prListURL, filterOptions{
240240
entity: "pr",
241241
state: state,
@@ -246,7 +246,7 @@ func prList(cmd *cobra.Command, args []string) error {
246246
if err != nil {
247247
return err
248248
}
249-
fmt.Fprintf(cmd.ErrOrStderr(), "Opening %s in your browser.\n", displayURL(openURL))
249+
fmt.Fprintf(cmd.ErrOrStderr(), "Opening %s in your browser.\n", utils.DisplayURL(openURL))
250250
return utils.OpenInBrowser(openURL)
251251
}
252252

command/pr_create.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ func prCreate(cmd *cobra.Command, _ []string) error {
367367
}
368368
if connectedToTerminal(cmd) {
369369
// TODO could exceed max url length for explorer
370-
fmt.Fprintf(cmd.ErrOrStderr(), "Opening %s in your browser.\n", displayURL(openURL))
370+
fmt.Fprintf(cmd.ErrOrStderr(), "Opening %s in your browser.\n", utils.DisplayURL(openURL))
371371
}
372372
return utils.OpenInBrowser(openURL)
373373
} else {
@@ -447,7 +447,7 @@ func withPrAndIssueQueryParams(baseURL, title, body string, assignees, labels, p
447447
}
448448

449449
func generateCompareURL(r ghrepo.Interface, base, head, title, body string, assignees, labels, projects []string, milestone string) (string, error) {
450-
u := generateRepoURL(r, "compare/%s...%s?expand=1", base, head)
450+
u := ghrepo.GenerateRepoURL(r, "compare/%s...%s?expand=1", base, head)
451451
url, err := withPrAndIssueQueryParams(u, title, body, assignees, labels, projects, milestone)
452452
if err != nil {
453453
return "", err

0 commit comments

Comments
 (0)