Skip to content

Commit

Permalink
Merge pull request #7 from xebialabs-community/xlr8
Browse files Browse the repository at this point in the history
Xlr8
  • Loading branch information
jdewinne authored Oct 26, 2018
2 parents cb339e2 + 07eb6ea commit 1816ae8
Show file tree
Hide file tree
Showing 18 changed files with 108 additions and 91 deletions.
10 changes: 9 additions & 1 deletion .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
engines:
plugins:
duplication:
enabled: true
config:
Expand All @@ -10,10 +10,18 @@ engines:
- php
fixme:
enabled: true
checks:
TODO:
enabled: false
radon:
enabled: true
config:
python_version: 2
pep8:
enabled: true
checks:
E501:
enabled: false
ratings:
paths:
- "**.inc"
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ deploy:
skip_cleanup: true
on:
tags: true
branch: master
all_branches: true
repo: xebialabs-community/xlr-bitbucket-plugin
10 changes: 5 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ apply plugin: 'eclipse'
apply plugin: 'maven'

xlDocker {
compileImage = 'xebialabs/xlr_dev_compile'
compileVersion = 'v7.5.0.1'
runImage = 'xebialabs/xlr_dev_run'
runVersion = 'v7.5.0.1'
compileImage = 'xebialabsunsupported/xlr_dev_compile'
compileVersion = '8.2.0-1'
runImage = 'xebialabsunsupported/xlr_dev_run'
runVersion = '8.2.0-1'
runPortMapping = '15516:5516'
}

Expand All @@ -30,7 +30,7 @@ if (!project.hasProperty('release.useLastTag')) {

license {
header rootProject.file('License.md')
strictCheck false
strictCheck true
ext.year = Calendar.getInstance().get(Calendar.YEAR)
ext.name = 'XEBIALABS'
}
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.3-bin.zip
2 changes: 1 addition & 1 deletion src/main/resources/bitbucket/BitbucketTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
method = str(task.getTaskType()).lower().replace('.', '_')
call = getattr(bitbucket, method)
response = call(locals())
for key,value in response.items():
for key, value in response.items():
locals()[key] = value
6 changes: 4 additions & 2 deletions src/main/resources/bitbucket/CommitTrigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import sys
import json


def findNewCommit(oldCommitMap, newCommitMap):
branch = ""
commitId = ""
Expand All @@ -34,14 +35,15 @@ def findNewCommit(oldCommitMap, newCommitMap):

return branch, commitId


if server is None:
print "No Bitbucket server provided."
sys.exit(1)

request = HttpRequest(server, username, password)
context = "/2.0/repositories/%s/refs" % (repo_full_name)
branches_path = "%s/%s?limit=1000" % (context, "branches")
response = request.get(branches_path, contentType = 'application/json')
response = request.get(branches_path, contentType='application/json')

if not response.isSuccessful():
if response.status == 404 and triggerOnInitialPublish:
Expand Down Expand Up @@ -74,7 +76,7 @@ def findNewCommit(oldCommitMap, newCommitMap):

branch, commitId = findNewCommit(oldCommit, newCommit)

if branchName == "" or (branchName != "" and branchName == branch ):
if branchName == "" or (branchName != "" and branchName == branch):
triggerState = newTriggerState

print("Bitbucket triggered release for %s-%s" % (branch, commitId))
12 changes: 8 additions & 4 deletions src/main/resources/bitbucket/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@
# 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.
#


import json
import os
import tempfile
import time
import requests
import StringIO
import zipfile
from com.xebialabs.xlr.ssl import LoaderUtil
from java.nio.file import Files, Paths, StandardCopyOption

import json, time
import requests, zipfile, StringIO
from org.apache.http.client import ClientProtocolException
from xlrelease.HttpRequest import HttpRequest
from xlrelease.CredentialsFallback import CredentialsFallback
from org.apache.http.client import ClientProtocolException


class BitbucketClient(object):
Expand Down Expand Up @@ -124,5 +127,6 @@ def extract_file_from_jar(config_file):
else:
return None


if 'REQUESTS_CA_BUNDLE' not in os.environ:
set_ca_bundle_path()
15 changes: 8 additions & 7 deletions src/main/resources/bitbucket/push_webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,32 @@
from java.util import HashMap


def handle_request(event, template_filter = None):
def handle_request(event, template_filter=None):
try:
if event["push"]:
logger.info("Found push event for template %s " % template_filter)
handle_push_event(event, template_filter)
except:
except Exception:
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"]
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))
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)



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, current_commit_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 @@ -49,7 +49,7 @@ 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 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)
Expand Down Expand Up @@ -83,4 +83,5 @@ def start_pr_release(repo_full_name, pr_number, pr_title, comment):
response.entity = started_release
logger.info("Started release %s to merge pull request %s" % (started_release.getId(), pr_number))


handle_request(request.entity, request.query['template'])
File renamed without changes
6 changes: 4 additions & 2 deletions src/main/resources/stash/CommitTrigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import sys
import json


def findNewCommit(oldCommitMap, newCommitMap):
branch = ""
commitId = ""
Expand All @@ -34,14 +35,15 @@ def findNewCommit(oldCommitMap, newCommitMap):

return branch, commitId


if server is None:
print "No Bitbucket server provided."
sys.exit(1)

request = HttpRequest(server, username, password)
context = "/rest/api/1.0/projects/%s/repos/%s" % (project, repository)
branches_path = "%s/%s?limit=1000" % (context, "branches")
response = request.get(branches_path, contentType = 'application/json')
response = request.get(branches_path, contentType='application/json')

if not response.isSuccessful():
if response.status == 404 and triggerOnInitialPublish:
Expand Down Expand Up @@ -75,6 +77,6 @@ def findNewCommit(oldCommitMap, newCommitMap):

branch, commitId = findNewCommit(oldCommit, newCommit)

if not branchName or (branchName and branchName == branch ):
if not branchName or (branchName and branchName == branch):
triggerState = newTriggerState
print("Bitbucket triggered release for %s-%s" % (branch, commitId))
Loading

0 comments on commit 1816ae8

Please sign in to comment.