Skip to content

Commit

Permalink
Merge pull request #5 from Clever/show-commit-status
Browse files Browse the repository at this point in the history
show commit status
  • Loading branch information
rgarcia authored Oct 31, 2017
2 parents c115e0d + e0c528c commit 3382be4
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 8 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.6
0.0.7
5 changes: 3 additions & 2 deletions cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ func printStatus(repos []string) {
status, details := getRepoStatus(r)
d2 := strings.TrimSpace(details)
d3 := strings.Join(strings.Split(d2, "\n"), " ")
if len(d3) > 40 {
d3 = d3[:60] + "..."
if len(d3) > 100 {
d3 = d3[:100] + "..."
}
fmt.Fprintln(out, joinWithTab(r, status, d3))
}
Expand Down Expand Up @@ -109,6 +109,7 @@ func getRepoStatus(repo string) (status, details string) {
return
}
status = "pushed"
details = pushOutput.String()

var mergeOutput merge.Output
if !(loadJSON(mergeOutputPath(repo), &mergeOutput) == nil && mergeOutput.Success) {
Expand Down
43 changes: 38 additions & 5 deletions push/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,29 @@ type Input struct {

// Output from Push()
type Output struct {
Success bool
CommitSHA string
PullRequestURL string
PullRequestNumber int
Success bool
CommitSHA string
PullRequestURL string
PullRequestNumber int
PullRequestCombinedStatus string // failure, pending, or success
PullRequestAssignee string
}

func (o Output) String() string {
s := "status:"
switch o.PullRequestCombinedStatus {
case "failure":
s += "❌"
case "pending":
s += "🕐"
case "success":
s += "✅"
default:
s += "?"
}

s += fmt.Sprintf(" assignee:%s %s", o.PullRequestAssignee, o.PullRequestURL)
return s
}

// Push pushes the commit to Github and opens a pull request
Expand Down Expand Up @@ -87,9 +106,23 @@ func Push(ctx context.Context, input Input) (Output, error) {
return Output{Success: false}, err
}
}

// get combined commit status
cs, _, err := client.Repositories.GetCombinedStatus(ctx, input.RepoOwner, input.RepoName, *pr.Head.SHA, nil)
if err != nil {
return Output{Success: false}, err
}

// TODO: if pr title != PRMessage, update it

return Output{Success: true, CommitSHA: *pr.Head.SHA, PullRequestNumber: *pr.Number, PullRequestURL: *pr.HTMLURL}, nil
return Output{
Success: true,
CommitSHA: *pr.Head.SHA,
PullRequestNumber: *pr.Number,
PullRequestURL: *pr.HTMLURL,
PullRequestCombinedStatus: *cs.State,
PullRequestAssignee: input.PRAssignee,
}, nil
}

func findOrCreatePR(ctx context.Context, client *github.Client, owner string, name string, pull *github.NewPullRequest) (*github.PullRequest, error) {
Expand Down

0 comments on commit 3382be4

Please sign in to comment.