@@ -4,11 +4,14 @@ import (
4
4
"golang.org/x/oauth2"
5
5
"golang.org/x/net/context"
6
6
"github.com/shurcooL/githubql"
7
+ "github.com/google/go-github/github"
8
+ "net/http"
7
9
)
8
10
9
11
type githubManager struct {
10
- Context context.Context
11
- Client * githubql.Client
12
+ Context context.Context
13
+ Client * githubql.Client
14
+ HttpClient * http.Client
12
15
}
13
16
14
17
func New (githubAccessToken string ) (* githubManager ) {
@@ -19,7 +22,7 @@ func New(githubAccessToken string) (*githubManager) {
19
22
httpClient := oauth2 .NewClient (ctx , src )
20
23
client := githubql .NewClient (httpClient )
21
24
22
- return & githubManager {Context : ctx , Client : client }
25
+ return & githubManager {Context : ctx , Client : client , HttpClient : httpClient }
23
26
}
24
27
25
28
func (gm * githubManager ) GetCommits (owner , repo , branch string , lastCommitsNumber int ) ([]Commit , error ) {
@@ -72,6 +75,26 @@ func PickFirstParentCommits(fullCommitsList []Commit) ([]Commit) {
72
75
return firstParentCommits
73
76
}
74
77
78
+ // TODO remove v3 client when implemented in v4
79
+ func (gm * githubManager ) ChangeBranchHead (owner , repo , branch , sha string , force bool ) (error ) {
80
+ httpClient := gm .HttpClient
81
+
82
+ client := github .NewClient (httpClient )
83
+ ref , _ , err := client .Git .GetRef (gm .Context , owner , repo , "heads/" + branch )
84
+ if nil != err {
85
+ return & Error {Message : "Can not update branch head because: " + err .Error (), PreviousError : err }
86
+ }
87
+
88
+ ref .GetObject ().SHA = & sha
89
+
90
+ ref , _ , err = client .Git .UpdateRef (gm .Context , owner , repo , ref , force )
91
+ if nil != err {
92
+ return & Error {Message : "Can not update branch head because: " + err .Error (), PreviousError : err }
93
+ }
94
+
95
+ return nil
96
+ }
97
+
75
98
func hydrateCommits (q * githubQuery ) ([]Commit ) {
76
99
var fullCommitsList []Commit
77
100
for _ , edge := range q .Repository .Ref .Target .Commit .History .Edges {
@@ -87,6 +110,7 @@ func hydrateCommits(q *githubQuery) ([]Commit) {
87
110
Message : string (edge .Node .Message ),
88
111
Parents : parents ,
89
112
StatusSuccess : bool (edge .Node .Status .State == githubql .String (githubql .StatusStateSuccess )),
113
+ PushedDate : edge .Node .PushedDate .Time ,
90
114
})
91
115
}
92
116
0 commit comments