Skip to content

Commit

Permalink
Ensure OpenShift build names don't end in dash
Browse files Browse the repository at this point in the history
(cherry picked from commit d271b7d)
Signed-off-by: Tim Waugh <[email protected]>
  • Loading branch information
lcarva authored and twaugh committed Jan 11, 2017
1 parent 696505a commit 880a983
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
11 changes: 10 additions & 1 deletion osbs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,10 @@ def make_name_from_git(repo, branch, limit=53, separator='-'):
Assuming '-XXXX' (5 chars) and '-build' (6 chars) as default
suffixes, name should be limited to 53 chars (64 - 11).
Since OpenShift rejects names that end in dash, the
generated name may be trimmed resulting in a name shorter
than the limit.
:param repo: str, the git repository to be used
:param branch: str, the git branch to be used
:param limit: int, max name length
Expand Down Expand Up @@ -332,7 +336,12 @@ def make_name_from_git(repo, branch, limit=53, separator='-'):
repo = ''.join(repo_chars)
branch = ''.join(branch_chars)

return repo + separator + branch
name = repo + separator + branch

while name.endswith('-'):
name = name[:-1]

return name


def get_instance_token_file_name(instance):
Expand Down
3 changes: 3 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ def test_get_time_from_rfc3339_valid(rfc3339, seconds, tz):
('spam', 'b', 10, '-', 'spam-b'),
('spam', 'bacon', 10, '^^^', 'spam^^^bac'),
('spam', '', 10, '-', 'spam-unkno'),
('spam', 'baco-n', 10, '-', 'spam-baco'),
('spam', 'ba---n', 10, '-', 'spam-ba'),
('spam', '-----n', 10, '-', 'spam'),
('https://github.com/blah/spam.git', 'bacon', 10, '-', 'spam-bacon'),
])
def test_make_name_from_git(repo, branch, limit, separator, expected):
Expand Down

0 comments on commit 880a983

Please sign in to comment.