Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the trailing slash in our repo regexs #6956

Merged
merged 6 commits into from
Apr 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions readthedocs/builds/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,6 @@ def get_github_url(
user, repo = get_github_username_repo(repo_url)
if not user and not repo:
return ''
repo = repo.rstrip('/')

if not filename:
# If there isn't a filename, we don't need a suffix
Expand Down Expand Up @@ -538,7 +537,6 @@ def get_gitlab_url(
user, repo = get_gitlab_username_repo(repo_url)
if not user and not repo:
return ''
repo = repo.rstrip('/')

if not filename:
# If there isn't a filename, we don't need a suffix
Expand Down Expand Up @@ -567,7 +565,6 @@ def get_bitbucket_url(self, docroot, filename, source_suffix='.rst'):
user, repo = get_bitbucket_username_repo(repo_url)
if not user and not repo:
return ''
repo = repo.rstrip('/')

if not filename:
# If there isn't a filename, we don't need a suffix
Expand Down Expand Up @@ -803,7 +800,6 @@ def get_commit_url(self):
if not user and not repo:
return ''

repo = repo.rstrip('/')
return GITHUB_PULL_REQUEST_COMMIT_URL.format(
user=user,
repo=repo,
Expand All @@ -815,7 +811,6 @@ def get_commit_url(self):
if not user and not repo:
return ''

repo = repo.rstrip('/')
return GITLAB_MERGE_REQUEST_COMMIT_URL.format(
user=user,
repo=repo,
Expand All @@ -829,7 +824,6 @@ def get_commit_url(self):
if not user and not repo:
return ''

repo = repo.rstrip('/')
return GITHUB_COMMIT_URL.format(
user=user,
repo=repo,
Expand All @@ -840,7 +834,6 @@ def get_commit_url(self):
if not user and not repo:
return ''

repo = repo.rstrip('/')
return GITLAB_COMMIT_URL.format(
user=user,
repo=repo,
Expand All @@ -851,7 +844,6 @@ def get_commit_url(self):
if not user and not repo:
return ''

repo = repo.rstrip('/')
return BITBUCKET_COMMIT_URL.format(
user=user,
repo=repo,
Expand Down
7 changes: 5 additions & 2 deletions readthedocs/oauth/services/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,9 @@ def send_build_status(self, build, commit, state):
resp = None

try:
statuses_url = f'https://api.github.com/repos/{owner}/{repo}/statuses/{commit}'
resp = session.post(
f'https://api.github.com/repos/{owner}/{repo}/statuses/{commit}',
statuses_url,
data=json.dumps(data),
headers={'content-type': 'application/json'},
)
Expand All @@ -461,9 +462,11 @@ def send_build_status(self, build, commit, state):
if resp.status_code in [401, 403, 404]:
log.info(
'GitHub project does not exist or user does not have '
'permissions: project=%s, user=%s',
'permissions: project=%s, user=%s, status=%s, url=%s',
project,
self.user,
resp.status_code,
statuses_url,
)
return False

Expand Down
8 changes: 7 additions & 1 deletion readthedocs/projects/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,17 +312,23 @@

GITHUB_REGEXS = [
re.compile(r'github.com/(.+)/(.+)(?:\.git){1}$'),
# This must come before the one without a / to make sure we don't capture the /
re.compile(r'github.com/(.+)/(.+)/'),
re.compile(r'github.com/(.+)/(.+)'),
re.compile(r'github.com:(.+)/(.+)\.git$'),
]
BITBUCKET_REGEXS = [
re.compile(r'bitbucket.org/(.+)/(.+)\.git$'),
re.compile(r'@bitbucket.org/(.+)/(.+)\.git$'),
re.compile(r'bitbucket.org/(.+)/(.+)/?'),
# This must come before the one without a / to make sure we don't capture the /
re.compile(r'bitbucket.org/(.+)/(.+)/'),
re.compile(r'bitbucket.org/(.+)/(.+)'),
re.compile(r'bitbucket.org:(.+)/(.+)\.git$'),
]
GITLAB_REGEXS = [
re.compile(r'gitlab.com/(.+)/(.+)(?:\.git){1}$'),
# This must come before the one without a / to make sure we don't capture the /
re.compile(r'gitlab.com/(.+)/(.+)/'),
re.compile(r'gitlab.com/(.+)/(.+)'),
re.compile(r'gitlab.com:(.+)/(.+)\.git$'),
]
Expand Down
2 changes: 2 additions & 0 deletions readthedocs/projects/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2179,6 +2179,8 @@ def send_build_status(build_pk, commit, status):
build = Build.objects.get(pk=build_pk)
provider_name = build.project.git_provider_name

log.info('Sending build status. build=%s, project=%s', build.pk, build.project.slug)

if provider_name in [GITHUB_BRAND, GITLAB_BRAND]:
# get the service class for the project e.g: GitHubService.
service_class = build.project.git_service_class()
Expand Down
6 changes: 4 additions & 2 deletions readthedocs/rtd_tests/tests/test_oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,11 @@ def test_send_build_status_404_error(self, session, mock_logger):
self.assertFalse(success)
mock_logger.info.assert_called_with(
'GitHub project does not exist or user does not have '
'permissions: project=%s, user=%s',
'permissions: project=%s, user=%s, status=%s, url=%s',
self.project,
self.user
self.user,
404,
'https://api.github.com/repos/pypa/pip/statuses/297'
)

@mock.patch('readthedocs.oauth.services.github.log')
Expand Down