@@ -122,6 +122,24 @@ def remove_label(self, pull_request, name):
122
122
123
123
request ('DELETE' , url )
124
124
125
+ @guard ('core' )
126
+ def create_ref (self , refspec , revision ):
127
+ url = '{}/repos/{}/git/refs' .format (self ._host , self ._github_project )
128
+
129
+ logger .info ('Creating ref "{}" ({})' .format (refspec , revision ))
130
+
131
+ request ('POST' , url , { 'ref' : refspec , 'sha' : revision })
132
+
133
+ @guard ('core' )
134
+ def update_ref (self , refspec , revision ):
135
+ url = '{}/repos/{}/git/refs/{}' .format (
136
+ self ._host , self ._github_project , refspec
137
+ )
138
+
139
+ logger .info ('Updating ref "{}" ({})' .format (refspec , revision ))
140
+
141
+ request ('PATCH' , url , { 'sha' : revision })
142
+
125
143
@guard ('core' )
126
144
def create_deployment (self , ref ):
127
145
url = '{}/repos/{}/deployments' .format (
@@ -163,9 +181,6 @@ def get_revision(self, refspec):
163
181
164
182
return output .split ()[0 ]
165
183
166
- def update_ref (self , refspec , revision ):
167
- raise NotImplementedError ()
168
-
169
184
def delete_ref (self , refspec ):
170
185
logger .info ('Deleting ref "{}"' .format (refspec ))
171
186
@@ -214,11 +229,15 @@ def main(host, github_project, repository):
214
229
if not has_label (pull_request ):
215
230
project .add_label (pull_request , LABEL )
216
231
217
- if revision_labeled != latest_revision :
218
- remote .update_ref (refspec_open , latest_revision )
232
+ if revision_labeled is None :
233
+ project .create_ref (refspec_labeled , latest_revision )
234
+ elif revision_labeled != latest_revision :
235
+ project .update_ref (refspec_labeled , latest_revision )
219
236
220
- if revision_open != latest_revision :
221
- remote .update_ref (refspec_labeled , latest_revision )
237
+ if revision_open is None :
238
+ project .create_ref (refspec_open , latest_revision )
239
+ elif revision_open != latest_revision :
240
+ project .update_ref (refspec_open , latest_revision )
222
241
else :
223
242
logger .info ('Pull request should not be mirrored' )
224
243
0 commit comments