diff --git a/endpoints/trigger.py b/endpoints/trigger.py index 053d47d57..61c5e7ef8 100644 --- a/endpoints/trigger.py +++ b/endpoints/trigger.py @@ -231,15 +231,16 @@ class GithubBuildTrigger(BuildTrigger): return repos_by_org - def matches_branch(self, branch_name, regex): + def matches_ref(self, ref, regex): + match_string = ref.split('/', 1)[1] if not regex: return False - m = regex.match(branch_name) + m = regex.match(match_string) if not m: return False - return len(m.group(0)) == len(branch_name) + return len(m.group(0)) == len(match_string) def list_build_subdirs(self, auth_token, config): gh_client = self._get_client(auth_token) @@ -250,11 +251,11 @@ class GithubBuildTrigger(BuildTrigger): # Find the first matching branch. branches = None - if 'branch_regex' in config: + if 'branchtag_regex' in config: try: - regex = re.compile(config['branch_regex']) + regex = re.compile(config['branchtag_regex']) branches = [branch.name for branch in repo.get_branches() - if self.matches_branch(branch.name, regex)] + if self.matches_ref('refs/heads/' + branch.name, regex)] except: pass @@ -370,14 +371,13 @@ class GithubBuildTrigger(BuildTrigger): commit_sha = payload['head_commit']['id'] commit_message = payload['head_commit'].get('message', '') - if 'branch_regex' in config: + if 'branchtag_regex' in config: try: - regex = re.compile(config['branch_regex']) + regex = re.compile(config['branchtag_regex']) except: regex = re.compile('.*') - branch = ref.split('/')[-1] - if not self.matches_branch(branch, regex): + if not self.matches_ref(ref, regex): raise SkipRequestException() if should_skip_commit(commit_message): @@ -414,6 +414,19 @@ class GithubBuildTrigger(BuildTrigger): def list_field_values(self, auth_token, config, field_name): + if field_name == 'refs': + branches = self.list_field_values(auth_token, config, 'branch_name') + tags = self.list_field_values(auth_token, config, 'tag_name') + + return ([{'kind': 'branch', 'name': b} for b in branches] + + [{'kind': 'tag', 'name': tag} for tag in tags]) + + if field_name == 'tag_name': + gh_client = self._get_client(auth_token) + source = config['build_source'] + repo = gh_client.get_repo(source) + return [tag.name for tag in repo.get_tags()] + if field_name == 'branch_name': gh_client = self._get_client(auth_token) source = config['build_source'] diff --git a/static/css/quay.css b/static/css/quay.css index 58e53af60..f0bf4883d 100644 --- a/static/css/quay.css +++ b/static/css/quay.css @@ -19,6 +19,18 @@ } } +.dropdown.input-group-addon { + padding: 0px; + border: 0px; + background-color: transparent; + text-align: left; +} + +.dropdown.input-group-addon .dropdown-toggle { + border-left: 0px; + border-top-left-radius: 0px; + border-bottom-left-radius: 0px; +} #quay-logo { width: 100px; @@ -4109,20 +4121,37 @@ pre.command:before { border-bottom-left-radius: 0px; } -.trigger-setup-github-element .branch-reference.not-match { - color: #ccc !important; +.trigger-setup-github-element .ref-reference { + color: #ccc; } -.trigger-setup-github-element .branch-reference.not-match a { - color: #ccc !important; +.trigger-setup-github-element .ref-reference span { + cursor: pointer; text-decoration: line-through; } -.trigger-setup-github-element .branch-filter { +.trigger-setup-github-element .ref-reference:hover { + color: #3276b1; +} + +.trigger-setup-github-element .ref-reference:hover span { + text-decoration: none; +} + +.trigger-setup-github-element .ref-reference.match { + color: black; +} + +.trigger-setup-github-element .ref-reference.match span { + text-decoration: none; + cursor: default; +} + +.trigger-setup-github-element .ref-filter { white-space: nowrap; } -.trigger-setup-github-element .branch-filter span { +.trigger-setup-github-element .ref-filter span { display: inline-block; } @@ -4145,19 +4174,37 @@ pre.command:before { padding-left: 6px; } -.trigger-setup-github-element .matching-branches { +.trigger-setup-github-element .matching-refs { margin: 0px; padding: 0px; margin-left: 10px; display: inline-block; } -.trigger-setup-github-element .matching-branches li:before { +.trigger-setup-github-element .ref-matches { + padding-left: 70px; + position: relative; + margin-bottom: 10px; +} + +.trigger-setup-github-element .ref-matches .kind { + font-weight: bold; + position: absolute; + top: 0px; + left: 0px; +} + +.trigger-setup-github-element .matching-refs.tags li:before { + content: "\f02b"; + font-family: FontAwesome; +} + +.trigger-setup-github-element .matching-refs.branches li:before { content: "\f126"; font-family: FontAwesome; } -.trigger-setup-github-element .matching-branches li { +.trigger-setup-github-element .matching-refs li { list-style: none; display: inline-block; margin-left: 10px; @@ -4333,11 +4380,14 @@ pre.command:before { } .trigger-pull-credentials { - margin-top: 4px; padding-left: 26px; font-size: 12px; } +.trigger-pull-credentials .entity-reference { + margin-left: 10px; +} + .trigger-pull-credentials .context-tooltip { color: gray; margin-right: 4px; @@ -4345,7 +4395,8 @@ pre.command:before { .trigger-description .trigger-description-subtitle { display: inline-block; - margin-right: 34px; + width: 100px; + margin-bottom: 4px; } .trigger-option-section:not(:first-child) { diff --git a/static/directives/trigger-description.html b/static/directives/trigger-description.html index 4d9eb0930..91000dd1e 100644 --- a/static/directives/trigger-description.html +++ b/static/directives/trigger-description.html @@ -4,9 +4,9 @@ Push to GitHub repository {{ trigger.config.build_source }}
- Branches: - Matching Regular Expression {{ trigger.config.branch_regex }} - (All Branches) + Branches/Tags: + Matching Regular Expression {{ trigger.config.branchtag_regex }} + (All Branches and Tags)
diff --git a/static/directives/trigger-setup-github.html b/static/directives/trigger-setup-github.html index ba0aca2e7..bb5635a0e 100644 --- a/static/directives/trigger-setup-github.html +++ b/static/directives/trigger-setup-github.html @@ -10,19 +10,19 @@
- {{ currentRepo.repo }} + {{ currentRepo.repo }}
- Branches: + Branches and Tags: -
- (All Branches) - Regular Expression: {{ state.branchFilter }} +
+ (Build All) + Regular Expression: {{ state.branchTagFilter }}
@@ -68,45 +68,76 @@
- -
+ +
-
Please choose the branches to which this trigger will apply:
+
Please choose the branches and tags to which this trigger will apply:
-
+
- +
+
+ + +
+
+
-
- Branches: -
    + -
    + Tags: +
      +
    • + + {{ tagName }} + +
    • +
    + ... +
    +
    Warning: No branches found
    diff --git a/static/js/app.js b/static/js/app.js index 0cb133b67..a52d4566e 100644 --- a/static/js/app.js +++ b/static/js/app.js @@ -5258,25 +5258,41 @@ quayApp.directive('triggerSetupGithub', function () { controller: function($scope, $element, ApiService) { $scope.analyzeCounter = 0; $scope.setupReady = false; - + $scope.refs = null; $scope.branchNames = null; + $scope.tagNames = null; $scope.state = { - 'branchFilter': '', - 'hasBranchFilter': false, + 'branchTagFilter': '', + 'hasBranchTagFilter': false, 'isInvalidLocation': true, 'currentLocation': null }; - $scope.isMatchingBranch = function(branchName, filter) { + $scope.isMatching = function(kind, name, filter) { try { var patt = new RegExp(filter); } catch (ex) { return false; } - var m = branchName.match(patt); - return m && m[0].length == branchName.length; + var fullname = (kind + '/' + name); + var m = fullname.match(patt); + return m && m[0].length == fullname.length; + } + + $scope.addRef = function(kind, name) { + if ($scope.isMatching(kind, name, $scope.state.branchTagFilter)) { + return; + } + + var newFilter = kind + '/' + name; + var existing = $scope.state.branchTagFilter; + if (existing) { + $scope.state.branchTagFilter = '(' + existing + ')|(' + newFilter + ')'; + } else { + $scope.state.branchTagFilter = newFilter; + } } $scope.stepsCompleted = function() { @@ -5296,17 +5312,29 @@ quayApp.directive('triggerSetupGithub', function () { }, ApiService.errorDisplay('Cannot load repositories')); }; - $scope.loadBranches = function(callback) { + $scope.loadBranchesAndTags = function(callback) { var params = { 'repository': $scope.repository.namespace + '/' + $scope.repository.name, 'trigger_uuid': $scope.trigger['id'], - 'field_name': 'branch_name' + 'field_name': 'refs' }; ApiService.listTriggerFieldValues($scope.trigger['config'], params).then(function(resp) { - $scope.branchNames = resp['values']; + $scope.refs = resp['values']; + $scope.branchNames = []; + $scope.tagNames = []; + + for (var i = 0; i < $scope.refs.length; ++i) { + var ref = $scope.refs[i]; + if (ref.kind == 'branch') { + $scope.branchNames.push(ref.name); + } else { + $scope.tagNames.push(ref.name); + } + } + callback(); - }, ApiService.errorDisplay('Cannot load branch names')); + }, ApiService.errorDisplay('Cannot load branch and tag names')); }; $scope.loadLocations = function(callback) { @@ -5413,13 +5441,13 @@ quayApp.directive('triggerSetupGithub', function () { } }); - $scope.$watch('state.branchFilter', function(bf) { + $scope.$watch('state.branchTagFilter', function(bf) { if (!$scope.trigger) { return; } - if ($scope.state.hasBranchFilter) { - $scope.trigger['config']['branch_regex'] = bf; + if ($scope.state.hasBranchTagFilter) { + $scope.trigger['config']['branchtag_regex'] = bf; } else { - delete $scope.trigger['config']['branch_regex']; + delete $scope.trigger['config']['branchtag_regex']; } }); } diff --git a/static/partials/repo-admin.html b/static/partials/repo-admin.html index f22431232..aa0e008d3 100644 --- a/static/partials/repo-admin.html +++ b/static/partials/repo-admin.html @@ -260,7 +260,7 @@
- +