Пример #1
0
def set_repo_default_branch(spec, branch):
    request_data = {'id': f'refs/heads/{branch}'}
    return spec, call(
        f'/rest/api/1.0/projects/{spec[0]}/repos/{spec[1]}/branches/default',
        request_data,
        only_response_code=True,
        method='PUT',
    )
 def f(spec):
     project, repo = spec
     try:
         commits = call(f'/rest/api/1.0/projects/{project}'
                        f'/repos/{repo}/commits?limit=1&until={branch}')
         author_timestamp = commits['values'][0]['authorTimestamp']
     except HTTPError:
         # Does not have branch
         author_timestamp = None
     return spec, to_date(author_timestamp) if author_timestamp else None
Пример #3
0
def set_single_status(build_url, build_state):
    repo, status = build_state
    state = STATUS_SUCCESSFUL if status == Build.SUCCESS else STATUS_FAILED
    commit_id = [b.head for b in repo.branches
                 if b.name == repo.setup_branch][0]
    request_data = {'state': state, 'key': commit_id, 'url': build_url}
    return repo, commit_id, state, build_url, call(
        f'/rest/build-status/1.0/commits/{commit_id}',
        request_data,
        'POST',
        only_response_code=True)
Пример #4
0
def get_web_hooks(spec):
    return call(get_uri(spec))
Пример #5
0
def create_web_hook(spec, hook):
    return call(get_uri(spec),
                only_response_code=True,
                method='POST',
                request_data=hook)
Пример #6
0
def delete_web_hook(spec, hook_id):
    return call(f'{get_uri(spec)}/{hook_id}',
                only_response_code=True,
                method='DELETE')
Пример #7
0
def get_repos_page(project, limit, start):
    response = call(f'/rest/api/1.0/projects/{project}'
                    f'/repos?limit={limit}&start={start}')
    return response['size'], response['values'], response[
        'isLastPage'], response.get('nextPageStart', -1)
Пример #8
0
def get_repo_default_branch(spec):
    return spec, call(
        f'/rest/api/1.0/projects/{spec[0]}/repos/{spec[1]}/branches/default')
Пример #9
0
def get_branch_page(spec, branch, limit, start):
    response = call(
        f'/rest/api/1.0/projects/{spec[0]}/repos/{spec[1]}'
        f'/branches?filterText={branch}&limit={limit}&start={start}')
    return response['size'], response['values'], response[
        'isLastPage'], response.get('nextPageStart', -1)
Пример #10
0
def delete_repo(spec):
    return spec, call(
        f'/rest/api/1.0/projects/{spec[0]}/repos/{spec[1]}',
        method="DELETE",
    )
Пример #11
0
def enable_repo_web_hook(spec, url):
    uri = f'/rest/api/1.0/projects/{spec[0]}/repos/{spec[1]}' + \
          '/settings/hooks/com.atlassian.stash.plugin.stash-web-post-' + \
          'receive-hooks-plugin:postReceiveHook/enabled'
    request_data = {'hook-url-0': url}
    return spec, call(uri, request_data, 'PUT')
Пример #12
0
def get_tags_page(spec, tag, limit, start, order_by='MODIFICATION'):
    response = call(
        f'/rest/api/1.0/projects/{spec[0]}/repos/{spec[1]}/tags?'
        f'filterText={tag}&limit={limit}&start={start}&orderBy={order_by}')
    return response['size'], response['values'], response[
        'isLastPage'], response.get('nextPageStart', -1)
Пример #13
0
def create_repo(project, repo):
    uri = f'/rest/api/1.0/projects/{project}/repos'
    # request_data = f'{{"name":"{repo}","scmId":"git","forkable":true}}'
    request_data = {'name': repo, 'scmId': 'git', 'forkable': True}
    return call(uri, request_data, 'POST')
Пример #14
0
def fork_repo(spec, fork_project):
    uri = f'/rest/api/1.0/projects/{spec[0]}/repos/{spec[1]}'
    request_data = {'slug': spec[1], 'project': {'key': fork_project}}
    return spec, call(uri, request_data, 'POST')