コード例 #1
0
 def merge(organization: str, project: str, pull_id: int, sha: str) -> str:
     pull_request = (environment.repo(organization,
                                      project).get_pull(pull_id))
     method = 'squash' if pull_request.commits > 1 else 'rebase'
     branch = pull_request.base.ref
     pull_request.merge(merge_method=method, sha=sha)
     return branch
コード例 #2
0
 def from_committed(cls, organization: str, project: str, branch: str):
     return cls(project=project,
                clone_url=environment.repo(organization, project).clone_url,
                branch=branch)
コード例 #3
0
 def from_pull_request(cls, organization: str, project: str, pull_id: int):
     pull = environment.repo(organization, project).get_pull(pull_id)
     return cls(project=project,
                clone_url=pull.head.repo.clone_url,
                branch=pull.base.ref,
                source_branch=pull.head.ref)
コード例 #4
0
 def publish(cls, organization: str, project: str, branch: str):
     ghrepo = environment.repo(organization, project)
     wrap = wrapcreator.make_wrap(project, ghrepo.clone_url, branch)
     with tempfile.TemporaryDirectory() as tmp:
         cls._import_wrap(tmp, organization, wrap)
コード例 #5
0
 def _import_wrap(cls, tmp, organization: str, wrap: wrap.Wrap) -> None:
     wrappath = os.path.join(tmp, wrap.name + '.wrap')
     zippath = os.path.join(tmp, wrap.name + '.zip')
     with open(wrappath, 'w') as f:
         f.write(wrap.wrapfile_content)
     with open(zippath, 'wb') as f:
         f.write(wrap.zip)
     ghrepo = environment.repo(organization, wrap.name)
     tagname = f'{wrap.version}-{wrap.revision}'
     try:
         rel = ghrepo.get_release(tagname)
         print(f'Release {tagname!r} already exists')
     except github.GithubException:
         tag = ghrepo.create_git_tag(tag=tagname,
                                     message=tagname,
                                     type='commit',
                                     object=wrap.commit_sha)
         ghrepo.create_git_ref(f'refs/tags/{tag.tag}', tag.sha)
         rel = ghrepo.create_git_release(tag=tagname,
                                         name=tagname,
                                         message=tagname)
         print(f'Release {tagname!r} created')
     patch_label = 'patch.zip'
     wrap_label = 'upstream.wrap'
     patch_found = False
     wrap_found = False
     for a in rel.get_assets():
         if a.label == patch_label:
             patch_found = True
         elif a.label == wrap_label:
             wrap_found = True
         else:
             print(f'Removing unknown asset {a.label!r} / {a.name!r}')
             a.delete_asset()
     if not patch_found:
         # Reupload all assets since wrapfile remembers the hash of zipfile.
         for a in rel.get_assets():
             if a.label == wrap_label:
                 print(f'Deleting {a.label!r}')
                 a.delete_asset()
         print(f'Uploading {wrap_label!r}')
         rel.upload_asset(wrappath,
                          label=wrap_label,
                          content_type='text/plain')
         print(f'Uploading {patch_label!r}')
         rel.upload_asset(zippath,
                          label=patch_label,
                          content_type='application/zip')
     elif not wrap_found:
         assert patch_found
         for a in rel.get_assets():
             if a.label == patch_label:
                 with requests.get(a.browser_download_url) as rv:
                     rv.raise_for_status()
                     wrap.wrapfile_content = update_wrapfile(
                         wrap.wrapfile_content, rv.content)
         with open(wrappath, 'w') as f:
             f.write(wrap.wrapfile_content)
         print(f'Uploading {wrap_label!r}')
         rel.upload_asset(wrappath,
                          label=wrap_label,
                          content_type='text/plain')