@@ -122,6 +122,24 @@ def remove_label(self, pull_request, name):
122122
123123 request ('DELETE' , url )
124124
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+
125143 @guard ('core' )
126144 def create_deployment (self , ref ):
127145 url = '{}/repos/{}/deployments' .format (
@@ -163,9 +181,6 @@ def get_revision(self, refspec):
163181
164182 return output .split ()[0 ]
165183
166- def update_ref (self , refspec , revision ):
167- raise NotImplementedError ()
168-
169184 def delete_ref (self , refspec ):
170185 logger .info ('Deleting ref "{}"' .format (refspec ))
171186
@@ -214,11 +229,15 @@ def main(host, github_project, repository):
214229 if not has_label (pull_request ):
215230 project .add_label (pull_request , LABEL )
216231
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 )
219236
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 )
222241 else :
223242 logger .info ('Pull request should not be mirrored' )
224243
0 commit comments