Skip to content

Commit

Permalink
Merge pull request #28 from zvercodebender/master
Browse files Browse the repository at this point in the history
vierify trigger does not need a branch name
  • Loading branch information
Rick Broker authored Jul 29, 2020
2 parents d477026 + a8316f1 commit ae3d3f6
Show file tree
Hide file tree
Showing 15 changed files with 75 additions and 58 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ secrets.xlvals
supervisord.*
xlr-bitbucket-plugin.iml
deploy_key
test
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ processResources.configure {

license {
header rootProject.file('License.md')
excludes(["**/*.json", "**/echarts.min.js", "**/youtrack/**/*.*"])
excludes(["**/*.json", "**/echarts.min.js", "**/data/**/*", "**/docker/**/**/*"])
strictCheck false
ext.year = Calendar.getInstance().get(Calendar.YEAR)
ext.name = 'XEBIALABS'
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/stash/CommitsTile.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#

#reload(stash.Stash)
from stash.Stash import StashClient
import json

Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/stash/ContributionsTile.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
#
from stash.Stash import StashClient
import json
import org.slf4j.LoggerFactory as LoggerFactory

logger = LoggerFactory.getLogger("com.xebialabs.bitbucket-plugin")
if ( server == "" or project == "" or slug == "" ):
commits = []
else:
stash = StashClient.get_client(server, username, password)
data = json.loads(stash.stash_querycommits(locals()))
commits = data['parents']
commits = data['values']

authors = {}
committers = {}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/stash/Stash.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ def stash_querycommits(self, variables):
endpoint_get = "%s/?limit=%s" % (endpoint_get, variables['results_limit'])
if ( variables['tag'] is not None ):
endpoint_get = "%s&at=refs/tags/%s" % (endpoint_get, variables['tag'])
self.logger.warn("stash_querycommits->endpoint_get = %s " % endpoint_get)
response = self.api_call('GET', endpoint_get, contentType="application/json", Origin = variables['server']['url'])
data = response.getResponse()
self.logger.warn( "endpint = %s" % endpoint_get )
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/stash/TimelineTile.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def convertRFC3339ToDate(timestamp):

stash = StashClient.get_client(server, username, password)
data = json.loads(stash.stash_querycommits(locals()))
commits = data['parents']
commits = data['values']

# Compile data for summary view
commitsByDay = {}
Expand Down
20 changes: 10 additions & 10 deletions src/main/resources/stash/pr_webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ def start_new_branch_release(repo_full_name, branch_name, current_commit_hash, t
params = StartRelease()
params.setReleaseTitle("Release for BRANCH: %s/%s" % (repo_full_name,branch_name))
variables = HashMap()
variables.put('${repo_full_name}', '%s' % repo_full_name)
variables.put('${branch_name}', '%s' % branch_name)
variables.put('${current_commit_hash}', '%s' % current_commit_hash)
variables.put('repo_full_name', '%s' % repo_full_name)
variables.put('branch_name', '%s' % branch_name)
variables.put('current_commit_hash', '%s' % current_commit_hash)
params.setReleaseVariables(variables)
started_release = templateApi.start(template_id, params)
response.entity = started_release
Expand All @@ -83,13 +83,13 @@ def start_pr_release(proj_name, repo_name, pr_number, pr_title, comment, source_
params = StartRelease()
params.setReleaseTitle('Pull Request #%s: %s' % (pr_number, pr_title))
variables = HashMap()
variables.put('${pull_request_number}', '%s' % pr_number)
variables.put('${pull_request_title}', '%s' % pr_title)
variables.put('${repository_name}', '%s' % repo_name)
variables.put('${pull_request_comment}', '%s' % comment)
variables.put('${proj_name}', '%s' % proj_name)
variables.put('${source_hash}', '%s' % source_hash)
variables.put('${target_hash}', '%s' % target_hash)
variables.put('pull_request_number', '%s' % pr_number)
variables.put('pull_request_title', '%s' % pr_title)
variables.put('repository_name', '%s' % repo_name)
variables.put('pull_request_comment', '%s' % comment)
variables.put('proj_name', '%s' % proj_name)
variables.put('fromHash', '%s' % source_hash)
variables.put('toHash', '%s' % target_hash)
params.setReleaseVariables(variables)
started_release = templateApi.start(template_id, params)
response.entity = started_release
Expand Down
63 changes: 37 additions & 26 deletions src/main/resources/stash/push_webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,48 @@

from com.xebialabs.xlrelease.api.v1.forms import StartRelease
from java.util import HashMap
import json
import sys


def handle_request(event, template_filter = None):

print event
print template_filter
logger.info(str(event))
#try:
# if event["push"]:
# logger.info("Found push event for template %s " % template_filter)
# handle_push_event(event, template_filter)
#except:
# e = sys.exc_info()[1]
# msg = ("Could not parse payload, check your Bitbucket Webhook "
# "configuration. Error: %s. Payload:\n%s" % (e, event))
# logger.warn(msg)
# return
logger.info(json.dumps(event, indent=4, sort_keys=True))
try:
# event["eventKey"] == "repo:refs_changed"
if event["eventKey"]:
logger.info("Found push event for template %s " % template_filter)
handle_push_event(event, template_filter)
except:
e = sys.exc_info()[1]
msg = ("Could not parse payload, check your Bitbucket Webhook "
"configuration. Error: %s. Payload:\n%s" % (e, event))
logger.warn(msg)
return

def handle_push_event(event, template_filter):
repo_full_name = event["repository"]["full_name"]
changes = event["push"]["changes"]
for change in changes:
if change["new"] and change["new"]["type"] == "branch":
logger.info(" Handing new branch creation event for template %s " % template_filter)
branch_name = change["new"]["name"]
current_commit_hash = change["new"]["target"]["hash"]
logger.info("Starting release for new branch %s in repository %s from template %s" % ( repo_full_name, branch_name, template_filter))
start_new_branch_release(repo_full_name, branch_name, current_commit_hash, template_filter)
proj_name = event['repository']['project']['key']
logger.info("proj_name = %s" % proj_name)
branch_name = event['changes'][0]['ref']['displayId']
repo_name = event["repository"]['name']
logger.info("repo_name = %s" % repo_name)
source_hash = event['changes'][0]['fromHash']
logger.info("source_hash = %s" % source_hash)
target_hash = event['changes'][0]['toHash']
logger.info("target_hash = %s" % target_hash)
event_key = event['eventKey']
logger.info("eventKey = %s" % event_key)
repo_full_name = "%s/%s" % ( proj_name, repo_name )
logger.info("repo_full_name = %s" % repo_full_name)

logger.info("Starting release for new branch %s in repository %s from template %s" % ( branch_name, repo_full_name, template_filter))
start_new_branch_release(repo_full_name, branch_name, source_hash, target_hash, template_filter)


def start_new_branch_release(repo_full_name, branch_name, current_commit_hash, template_filter = None):

def start_new_branch_release(repo_full_name, branch_name, source_hash, target_hash, template_filter = None):
templates = templateApi.getTemplates(template_filter)
if not templates:
raise Exception('Could not find any templates by tag [pull_request_merger]. '
Expand All @@ -53,15 +63,16 @@ def start_new_branch_release(repo_full_name, branch_name, current_commit_hash, t
template_id = templates[0].id

params = StartRelease()
params.setReleaseTitle("Release for BRANCH: %s/%s" % (repo_full_name,branch_name))
params.setReleaseTitle("Release for: %s/%s" % (repo_full_name,branch_name))
variables = HashMap()
variables.put('${repo_full_name}', '%s' % repo_full_name)
variables.put('${branch_name}', '%s' % branch_name)
variables.put('${current_commit_hash}', '%s' % current_commit_hash)
variables.put('repo_full_name', '%s' % repo_full_name)
variables.put('branch_name', '%s' % branch_name)
variables.put('fromHash', '%s' % source_hash)
variables.put('toHash', '%s' % target_hash)
params.setReleaseVariables(variables)
started_release = templateApi.start(template_id, params)
response.entity = started_release
logger.info("Started Release %s for BRANCH: %s/%s" % (started_release.getId(), repo_full_name, branch_name))
logger.info("Started Release %s for: %s/%s" % (started_release.getId(), repo_full_name, branch_name))


def start_pr_release(repo_full_name, pr_number, pr_title, comment):
Expand Down
8 changes: 4 additions & 4 deletions src/main/resources/synthetic.xml
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@
<property name="project" category="input" required="true" label="Project Name"/>
<property name="slug" category="input" required="true" label="Project Slug" />
<property name="branch" category="input" required="false" label="Branch Name" description="If not provided, the default branch will be used" default="master"/>
<property name="tag" category="input" required="true" label="Tag Name" />
<property name="tag" category="input" required="false" label="Tag Name" />
<property name="results_limit" category="input" kind="integer" required="true" label="Results Limit" default="100" description="Upper limit on the number of pull requests to return from the query."/>
</type>

Expand All @@ -306,7 +306,7 @@
<property name="project" category="input" required="true" label="Project Name"/>
<property name="slug" category="input" required="true" label="Project Slug" />
<property name="branch" category="input" required="false" label="Branch Name" description="If not provided, the default branch will be used" default="master"/>
<property name="tag" category="input" required="true" label="Tag Name" />
<property name="tag" category="input" required="false" label="Tag Name" />
<property name="results_limit" category="input" kind="integer" required="true" label="Results Limit" default="100" description="Upper limit on the number of pull requests to return from the query."/>
</type>

Expand All @@ -322,7 +322,7 @@
<property name="project" category="input" required="true" label="Project Name"/>
<property name="slug" category="input" required="true" label="Project Slug" />
<property name="branch" category="input" required="false" label="Branch Name" description="If not provided, the default branch will be used" default="master"/>
<property name="tag" category="input" required="true" label="Tag Name" />
<property name="tag" category="input" required="false" label="Tag Name" />
<property name="results_limit" category="input" kind="integer" required="true" label="Results Limit" default="100" description="Upper limit on the number of pull requests to return from the query."/>
</type>

Expand Down Expand Up @@ -350,4 +350,4 @@
</enum-values>
</property>
</type>
</synthetic>
</synthetic>
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
};
window.addEventListener("xlrelease.load", function () {
window.xlrelease.queryTileData(function (response) {
var commits = response.data.data.commits.parents;
var commits = response.data.data.commits.values;
commits.forEach(function (commit) {
$("#commits").append(
'<tr>' +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<script>
window.addEventListener("xlrelease.load", function () {
window.xlrelease.queryTileData(function (response) {
var commits = response.data.data.commits.parents;
var commits = response.data.data.commits.values;
commits.forEach(function (commit) {
var d = new Date( commit.authorTimestamp );
var formattedDate = d.getDate() + "-" + (d.getMonth() + 1) + "-" + d.getFullYear();
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
bitbucket:
image: blacklabelops/bitbucket
image: blacklabelops/bitbucket:5.15.1
volumes:
- ./bitbucket/data:/var/atlassian/bitbucket
ports:
Expand Down
1 change: 1 addition & 0 deletions src/test/resources/yaml/xebialabs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ metadata:
- xebialabs/xlr-bitbucket-template.yaml
- xebialabs/xlr-stash-template.yaml
- xebialabs/xlr-pullrequest.yaml
- xebialabs/pr-webook.yaml
1 change: 1 addition & 0 deletions src/test/resources/yaml/xebialabs/xlr-pullrequest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ spec:
branchName: mydev
commitId: 9461da526022f28746c970ae02236994e0965f6e
branch: "22"
enabled: False
phases:
- phase: New Phase
tasks:
Expand Down
22 changes: 11 additions & 11 deletions src/test/resources/yaml/xebialabs/xlr-stash-dashboards.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ spec:
row: 2
col: 0
server: stash
project: TEST
slug: demo
project: DEMO
slug: test
- name: Stash Contributions Summary
type: stash.ContributionsTile
width: 2
height: 2
row: 0
col: 4
server: stash
project: TEST
slug: demo
branch: master
project: DEMO
slug: test
branch:
tag: ""
- name: Stash Commits Timeline
type: stash.TimelineTile
Expand All @@ -44,16 +44,16 @@ spec:
row: 0
col: 0
server: stash
project: TEST
slug: demo
branch: master
project: DEMO
slug: test
branch:
- name: Stash Merge Requests Summary
type: stash.MergeRequestsTile
width: 2
height: 2
row: 2
col: 4
server: stash
project: TEST
slug: demo
target_branch: master
project: DEMO
slug: test
target_branch:

0 comments on commit ae3d3f6

Please sign in to comment.