This repository has been archived by the owner on Oct 2, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgithub_ref_status.go
69 lines (54 loc) · 1.63 KB
/
github_ref_status.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package grim
// Copyright 2015 MediaMath <http://www.mediamath.com>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
import (
"context"
"fmt"
"github.com/google/go-github/github"
)
type refStatusState string
// These statuses model the statuses mentioned here: https://developer.github.com/v3/repos/statuses/#create-a-status
const (
RSPending refStatusState = "pending"
RSSuccess refStatusState = "success"
RSError refStatusState = "error"
RSFailure refStatusState = "failure"
)
func setRefStatus(token, owner, repo, ref string, statusBefore *github.RepoStatus) error {
client, err := getClientForToken(token)
if err != nil {
return err
}
repoStatus, res, err := client.Repositories.CreateStatus(context.Background(), owner, repo, ref, statusBefore)
if err != nil {
return err
}
if repoStatus == nil {
return fmt.Errorf("github client returned nil for repo status")
}
if repoStatus.ID == nil {
return fmt.Errorf("github client returned nil for repo status id")
}
return verifyHTTPCreated(res)
}
func getMergeCommitSha(token, owner, repo string, number int64) (string, error) {
client, err := getClientForToken(token)
if err != nil {
return "", err
}
u := fmt.Sprintf("repos/%v/%v/pulls/%d", owner, repo, int(number))
req, err := client.NewRequest("GET", u, nil)
if err != nil {
return "", err
}
pull := new(pullRequest)
_, err = client.Do(context.Background(), req, pull)
if err != nil {
return "", err
}
if pull == nil {
return "", fmt.Errorf("github client returned nil for pull request")
}
return pull.MergeCommitSha, nil
}