Merge remote-tracking branch 'origin/master' into pr-create-push-default

This commit is contained in:
Mislav Marohnić 2020-03-30 13:32:37 +02:00
commit da2116f8ee
17 changed files with 739 additions and 315 deletions

View file

@ -22,7 +22,9 @@ func TestPullRequest_ChecksStatus(t *testing.T) {
{ "status": "COMPLETED",
"conclusion": "FAILURE" },
{ "status": "COMPLETED",
"conclusion": "ACTION_REQUIRED" }
"conclusion": "ACTION_REQUIRED" },
{ "status": "COMPLETED",
"conclusion": "STALE" }
]
}
}
@ -32,8 +34,8 @@ func TestPullRequest_ChecksStatus(t *testing.T) {
eq(t, err, nil)
checks := pr.ChecksStatus()
eq(t, checks.Total, 7)
eq(t, checks.Pending, 2)
eq(t, checks.Total, 8)
eq(t, checks.Pending, 3)
eq(t, checks.Failing, 3)
eq(t, checks.Passing, 2)
}

View file

@ -120,7 +120,7 @@ func (pr *PullRequest) ChecksStatus() (summary PullRequestChecksStatus) {
summary.Passing++
case "ERROR", "FAILURE", "CANCELLED", "TIMED_OUT", "ACTION_REQUIRED":
summary.Failing++
case "EXPECTED", "REQUESTED", "QUEUED", "PENDING", "IN_PROGRESS":
case "EXPECTED", "REQUESTED", "QUEUED", "PENDING", "IN_PROGRESS", "STALE":
summary.Pending++
default:
panic(fmt.Errorf("unsupported status: %q", state))

View file

@ -2,6 +2,7 @@ package api
import (
"bytes"
"encoding/base64"
"encoding/json"
"errors"
"fmt"
@ -10,16 +11,18 @@ import (
"time"
"github.com/cli/cli/internal/ghrepo"
"github.com/cli/cli/utils"
)
// Repository contains information about a GitHub repo
type Repository struct {
ID string
Name string
URL string
CloneURL string
CreatedAt time.Time
Owner RepositoryOwner
ID string
Name string
Description string
URL string
CloneURL string
CreatedAt time.Time
Owner RepositoryOwner
IsPrivate bool
HasIssuesEnabled bool
@ -70,6 +73,7 @@ func GitHubRepo(client *Client, repo ghrepo.Interface) (*Repository, error) {
repository(owner: $owner, name: $name) {
id
hasIssuesEnabled
description
}
}`
variables := map[string]interface{}{
@ -323,3 +327,43 @@ func RepoCreate(client *Client, input RepoCreateInput) (*Repository, error) {
return &response.CreateRepository.Repository, nil
}
func RepositoryReadme(client *Client, fullName string) (string, error) {
type readmeResponse struct {
Name string
Content string
}
var readme readmeResponse
err := client.REST("GET", fmt.Sprintf("repos/%s/readme", fullName), nil, &readme)
if err != nil && !strings.HasSuffix(err.Error(), "'Not Found'") {
return "", fmt.Errorf("could not get readme for repo: %w", err)
}
decoded, err := base64.StdEncoding.DecodeString(readme.Content)
if err != nil {
return "", fmt.Errorf("failed to decode readme: %w", err)
}
readmeContent := string(decoded)
if isMarkdownFile(readme.Name) {
readmeContent, err = utils.RenderMarkdown(readmeContent)
if err != nil {
return "", fmt.Errorf("failed to render readme as markdown: %w", err)
}
}
return readmeContent, nil
}
func isMarkdownFile(filename string) bool {
// kind of gross, but i'm assuming that 90% of the time the suffix will just be .md. it didn't
// seem worth executing a regex for this given that assumption.
return strings.HasSuffix(filename, ".md") ||
strings.HasSuffix(filename, ".markdown") ||
strings.HasSuffix(filename, ".mdown") ||
strings.HasSuffix(filename, ".mkdown")
}