Skip to content

Commit

Permalink
Merge branch 'master' into cot-log
Browse files Browse the repository at this point in the history
  • Loading branch information
escapewindow authored Mar 19, 2019
2 parents 391c1ef + 6c36984 commit b7e6e5a
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [22.1.0] - 2019-03-19
### Added
- `event.repository.full_name` and `event.pull_request.base.repo.full_name` on `cot_verify` (for GitHub repos)

## [22.0.1] - 2019-03-13
### Fixed
- Allow snapcraft beta scope on mozilla-release
Expand Down
17 changes: 14 additions & 3 deletions scriptworker/cot/verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@
from scriptworker.context import Context
from scriptworker.ed25519 import ed25519_public_key_from_string, verify_ed25519_signature
from scriptworker.exceptions import CoTError, BaseDownloadError, ScriptWorkerEd25519Error, ScriptWorkerGPGException
from scriptworker.github import GitHubRepository
from scriptworker.github import (
GitHubRepository,
extract_github_repo_owner_and_name,
extract_github_repo_full_name,
)
from scriptworker.gpg import get_body, GPG
from scriptworker.log import contextual_log_handler
from scriptworker.task import (
extract_github_repo_owner_and_name,
get_action_callback_name,
get_and_check_project,
get_and_check_tasks_for,
Expand Down Expand Up @@ -1140,6 +1143,7 @@ async def _get_additional_github_releases_jsone_context(decision_link):
# This can't be done at the moment because some mobile projects still rely on the
# bad value
'clone_url': repo_url,
'full_name': extract_github_repo_full_name(repo_url),
'html_url': repo_url,
},
'release': {
Expand Down Expand Up @@ -1177,6 +1181,7 @@ def _get_additional_git_cron_jsone_context(decision_link):
# This can't be done at the moment because some mobile projects still rely on the
# bad value
'clone_url': repo,
'full_name': extract_github_repo_full_name(repo),
'html_url': repo,
},
'release': {
Expand Down Expand Up @@ -1220,6 +1225,11 @@ async def _get_additional_github_pull_request_jsone_context(decision_link):
'html_url': pull_request_data['head']['repo']['html_url'],
},
'pull_request': {
'base': {
'repo': {
'full_name': pull_request_data['base']['repo']['full_name'],
},
},
'head': {
'ref': pull_request_data['head']['ref'],
'sha': pull_request_data['head']['sha'],
Expand All @@ -1230,7 +1240,7 @@ async def _get_additional_github_pull_request_jsone_context(decision_link):
# This becomes a problem if a staging release was kicked off and the PR got
# updated in the meantime.
'pushed_at': get_push_date_time(task, source_env_prefix),
}
},
},
'title': pull_request_data['title'],
'number': pull_request_number,
Expand Down Expand Up @@ -1263,6 +1273,7 @@ async def _get_additional_github_push_jsone_context(decision_link):
return {
'event': {
'repository': {
'full_name': extract_github_repo_full_name(repo_url),
'html_url': repo_url,
'pushed_at': get_push_date_time(task, source_env_prefix),
},
Expand Down
18 changes: 18 additions & 0 deletions scriptworker/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,24 @@ def extract_github_repo_owner_and_name(url):
return repo_owner, _strip_trailing_dot_git(repo_name)


def extract_github_repo_full_name(url):
"""Given an URL, return the full name of it.
The full name is ``RepoOwner/RepoName``.
Args:
url (str): The URL to the GitHub repository
Raises:
ValueError: on url that aren't from github
Returns:
str: the full name.
"""
return '/'.join(extract_github_repo_owner_and_name(url))


def extract_github_repo_and_revision_from_source_url(url):
"""Given an URL, return the repo name and who owns it.
Expand Down
14 changes: 14 additions & 0 deletions scriptworker/test/test_cot_verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -1334,6 +1334,7 @@ async def test_populate_jsone_context_github_release(mocker, mobile_chain, mobil
'event': {
'repository': {
'clone_url': 'https://github.com/mozilla-mobile/focus-android',
'full_name': 'mozilla-mobile/focus-android',
'html_url': 'https://github.com/mozilla-mobile/focus-android',
},
'release': {
Expand Down Expand Up @@ -1371,6 +1372,7 @@ async def test_populate_jsone_context_git_cron(mobile_chain, mobile_cron_link, h
'event': {
'repository': {
'clone_url': 'https://github.com/mozilla-mobile/focus-android',
'full_name': 'mozilla-mobile/focus-android',
'html_url': 'https://github.com/mozilla-mobile/focus-android',
},
'release': {
Expand Down Expand Up @@ -1413,6 +1415,7 @@ async def test_populate_jsone_context_github_push(mocker, mobile_chain, mobile_g
assert context == {
'event': {
'repository': {
'full_name': 'mozilla-mobile/focus-android',
'html_url': 'https://github.com/mozilla-mobile/focus-android',
'pushed_at': '1549022400',
},
Expand Down Expand Up @@ -1450,6 +1453,11 @@ async def test_populate_jsone_context_github_pull_request(mocker, mobile_chain_p
}

github_repo_mock.get_pull_request.return_value = {
'base': {
'repo': {
'full_name': 'mozilla-mobile/focus-android',
},
},
'head': {
'ref': 'some-branch',
'repo': {
Expand Down Expand Up @@ -1489,6 +1497,11 @@ async def test_populate_jsone_context_github_pull_request(mocker, mobile_chain_p
'html_url': 'https://github.com/JohanLorenzo/focus-android',
},
'pull_request': {
'base': {
'repo': {
'full_name': 'mozilla-mobile/focus-android',
},
},
'head': {
'ref': 'some-branch',
'sha': 'somerevision',
Expand All @@ -1515,6 +1528,7 @@ async def test_populate_jsone_context_github_pull_request(mocker, mobile_chain_p
'tasks_for': 'github-pull-request',
}


@pytest.mark.asyncio
async def test_populate_jsone_context_fail(mobile_chain, mobile_github_release_link):
with pytest.raises(CoTError):
Expand Down
24 changes: 24 additions & 0 deletions scriptworker/test/test_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,30 @@ def test_extract_github_repo_owner_and_name(repo_url, expected_user, expected_re
assert github.extract_github_repo_owner_and_name(repo_url) == (expected_user, expected_repo_name)


@pytest.mark.parametrize('repo_url, expected, raises', ((
'https://github.com/mozilla-mobile/android-components',
'mozilla-mobile/android-components', False
), (
'https://github.com/mozilla-mobile/android-components.git',
'mozilla-mobile/android-components', False
), (
'https://github.com/JohanLorenzo/android-components',
'JohanLorenzo/android-components', False
), (
'https://github.com/JohanLorenzo/android-components/raw/0123456789abcdef0123456789abcdef01234567/.taskcluster.yml',
'JohanLorenzo/android-components', False
), (
'https://hg.mozilla.org/mozilla-central',
None, True
)))
def test_extract_github_repo_full_name(repo_url, expected, raises):
if raises:
with pytest.raises(ValueError):
github.extract_github_repo_full_name(repo_url)
else:
assert github.extract_github_repo_full_name(repo_url) == expected


@pytest.mark.parametrize('repo_url, expected_user, expected_repo_name, raises', ((
'https://github.com/JohanLorenzo/android-components/raw/0123456789abcdef0123456789abcdef01234567/.taskcluster.yml',
'https://github.com/JohanLorenzo/android-components', '0123456789abcdef0123456789abcdef01234567', False,
Expand Down
6 changes: 3 additions & 3 deletions version.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"version": [
22,
0,
1
1,
0
],
"version_string": "22.0.1"
"version_string": "22.1.0"
}

0 comments on commit b7e6e5a

Please sign in to comment.