Skip to content

Commit

Permalink
Merge pull request #2594 from civicrm/staging
Browse files Browse the repository at this point in the history
Sync master with staging
  • Loading branch information
mickadoo committed May 1, 2018
2 parents 6bcb2dc + 5367f88 commit 814af4c
Show file tree
Hide file tree
Showing 198 changed files with 10,359 additions and 4,949 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ hrjob/build
bin/setup.conf
hrabsence/build
/nbproject/private/
core-fork-last-commit-patched.txt

# Exclude sass cache from all extension directories
*/.sass-cache/
Expand Down
69 changes: 55 additions & 14 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pipeline {
stages {
stage('Pre-tasks execution') {
steps {
sendBuildStartdNotification()
sendBuildStartNotification()

// Print all Environment variables
sh 'printenv | sort'
Expand Down Expand Up @@ -189,26 +189,34 @@ pipeline {
/*
* Sends a notification when the build starts
*/
def sendBuildStartdNotification() {
def message = 'Building ' + getBuildTargetLink() + '. ' + getReportLink()
def sendBuildStartNotification() {
def msgHipChat = 'Building ' + getBuildTargetLink('hipchat') + '. ' + getReportLink('hipchat')
def msgSlack = 'Building ' + getBuildTargetLink('slack') + '. ' + getReportLink('slack')

sendHipchatNotification('YELLOW', message)
sendHipchatNotification('YELLOW', msgHipChat)
sendSlackNotification('warning', msgSlack)
}

/*
* Sends a notification when the build is completed successfully
*/
def sendBuildSuccessNotification() {
def message = getBuildTargetLink() + ' built successfully. Time: $BUILD_DURATION. ' + getReportLink()
sendHipchatNotification('GREEN', message)
def msgHipChat = getBuildTargetLink('hipchat') + ' built successfully. Time: $BUILD_DURATION. ' + getReportLink('hipchat')
def msgSlack = getBuildTargetLink('slack') + ' built successfully. Time: ' + getBuildDuration(currentBuild) + '. ' + getReportLink('slack')

sendHipchatNotification('GREEN', msgHipChat)
sendSlackNotification('good', msgSlack)
}

/*
* Sends a notification when the build fails
*/
def sendBuildFailureNotification() {
def message = 'Failed to build ' + getBuildTargetLink() + '. Time: $BUILD_DURATION. No. of failed tests: ${TEST_COUNTS,var=\"fail\"}. ' + getReportLink()
sendHipchatNotification('RED', message)
def msgHipChat = 'Failed to build ' + getBuildTargetLink('hipchat') + '. Time: $BUILD_DURATION. No. of failed tests: ${TEST_COUNTS,var=\"fail\"}. ' + getReportLink('hipchat')
def msgSlack = 'Failed to build ' + getBuildTargetLink('slack') + '. Time: ' + getBuildDuration(currentBuild) + '. ' + getReportLink('slack')

sendHipchatNotification('RED', msgHipChat)
sendSlackNotification('danger', msgSlack)
}

/*
Expand All @@ -218,16 +226,38 @@ def sendHipchatNotification(String color, String message) {
hipchatSend color: color, message: message, notify: true
}

/*
* Sends a notification to Slack
*/
def sendSlackNotification(String color, String message) {
slackSend color: color, message: message, notify: true
}

/*
* Returns the build duration without the "and counting" suffix
*/
def getBuildDuration(build) {
return build.durationString.replace(' and counting', '')
}

/*
* Returns a link to what is being built. If it's a PR, then it's a link to the pull request itself.
* If it's a branch, then it's a link in the format http://github.com/org/repo/tree/branch
*/
def getBuildTargetLink() {
if(buildIsForAPullRequest()) {
return "<a href=\"${env.CHANGE_URL}\">\"${env.CHANGE_TITLE}\"</a>"
def getBuildTargetLink(String client) {
def link = ''
def forPR = buildIsForAPullRequest()

switch (client) {
case 'hipchat':
link = forPR ? "<a href=\"${env.CHANGE_URL}\">\"${env.CHANGE_TITLE}\"</a>" : '<a href="' + getRepositoryUrlForBuildBranch() + '">"' + env.BRANCH_NAME + '"</a>'
break;
case 'slack':
link = forPR ? "<${env.CHANGE_URL}|${env.CHANGE_TITLE}>" : '<' + getRepositoryUrlForBuildBranch() + '|' + env.BRANCH_NAME + '>'
break;
}

return '<a href="' + getRepositoryUrlForBuildBranch() + '">"' + env.BRANCH_NAME + '"</a>'
return link
}

/*
Expand All @@ -250,8 +280,19 @@ def getRepositoryUrlForBuildBranch() {
/*
* Returns the Blue Ocean build report URL for the current job
*/
def getReportLink() {
return 'Click <a href="$BLUE_OCEAN_URL">here</a> to see the build report'
def getReportLink(String client) {
def link = ''

switch (client) {
case 'hipchat':
link = 'Click <a href="$BLUE_OCEAN_URL">here</a> to see the build report'
break
case 'slack':
link = "Click <${env.RUN_DISPLAY_URL}|here> to see the build report"
break
}

return link
}

def cloneCiviHRRepositories(String envBranch) {
Expand Down
131 changes: 131 additions & 0 deletions bin/apply-core-fork-patch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
#!/bin/bash

set -e

API_URL_BASE="https://api.github.com/repos/compucorp/civicrm-core"
LAST_COMMIT_PATCHED_FILE="core-fork-last-commit-patched.txt"
PATCH_FILE="fork-patch.diff"

civiRoot=""

#######################################
# Applies the patch on the core files
#
# Globals:
# $civiRoot
# $PATCH_FILE
# Arguments:
# None
# Returns:
# None
#######################################
applyPatch () {
(cd "$civiRoot" && patch -p1 < "$PATCH_FILE" >> /dev/null)
}

#######################################
# Creates a diff patch file by sending a request to the given GitHub API url
#
# Globals:
# $API_URL_BASE
# $civiRoot
# $PATCH_FILE
# Arguments:
# $1 base commit of the comparison
# $2 head commit of the comparison
# Returns:
# None
#######################################
createPatch () {
curl "$API_URL_BASE/compare/$1...$2" -s -H "Accept: application/vnd.github.v3.diff" > "$civiRoot/$PATCH_FILE"
}

#######################################
# Programmatically gets the current CiviCRM version
#
# Globals:
# None
# Arguments:
# None
# Returns:
# String
#######################################
getCiviVersion () {
drush eval "civicrm_initialize(); echo CRM_Utils_System::version();"
}

#######################################
# Uses Python to read the property's value of a JSON file
#
# Globals:
# None
# Arguments:
# $1 JSON file
# $2 property name
# Returns:
# String
#######################################
JSONValue () {
python -c "import sys, json; print json.load(sys.stdin)['$2']" < "$1"
}

#######################################
# Returns the civicrm root path
#
# Globals:
# None
# Arguments:
# None
# Returns:
# String
#######################################
setCivicrmRootPath () {
civiRoot=$(drush eval "civicrm_initialize(); echo \\Civi::paths()->getPath('[civicrm.root]/.')")
}

#######################################
# Updates the reference, in the LAST_COMMIT_PATCHED_FILE, to the last commit
# patched onto the core files
#
# Globals:
# $civiRoot
# $LAST_COMMIT_PATCHED_FILE
# Arguments:
# None
# Returns:
# None
#######################################
updateLastCommitPatched () {
# It uses the same file as temporary recipient of the full commit data
curl "$API_URL_BASE/commits/$1" -s > "$LAST_COMMIT_PATCHED_FILE"
sha=$(JSONValue "$LAST_COMMIT_PATCHED_FILE" "sha")

echo "$sha" > "$LAST_COMMIT_PATCHED_FILE"
}

# ---------------

touch -a $LAST_COMMIT_PATCHED_FILE
setCivicrmRootPath

civiVersion=$(getCiviVersion)
lastCommitPatched=$(cat "$LAST_COMMIT_PATCHED_FILE")
patchesBranch="$civiVersion-patches"
[ ! -z "$lastCommitPatched" ] && baseHead=$lastCommitPatched || baseHead=$civiVersion

echo "Fetching compucorp:civicrm-core patch..."
createPatch "$baseHead" "$patchesBranch"

if [ -s "$civiRoot/$PATCH_FILE" ]; then
echo "Applying compucorp:civicrm-core patch..."
applyPatch

echo "Updating reference to SHA of last commit patched..."
updateLastCommitPatched "$patchesBranch"

echo "Patch applied"
else
echo "Patch was empty, no diffs found"
fi

rm "$civiRoot/$PATCH_FILE"
64 changes: 64 additions & 0 deletions com.civicrm.hrjobroles/CRM/Hrjobroles/Upgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,70 @@ public function upgrade_1004() {
return TRUE;
}

/**
* Adds a submenu containing links to edit job role option groups
*
* @return bool
*/
public function upgrade_1005() {
$domain = CRM_Core_Config::domainID();
$params = ['return' => 'id', 'name' => 'Administer', 'domain_id' => $domain];
$administerId = (int) civicrm_api3('Navigation', 'getvalue', $params);

$permission = 'access CiviCRM';
$parent = $this->createNavItem('Job Roles', $permission, $administerId);
$parentId = $parent['id'];

// Weight cannot be set when creating for the first time
civicrm_api3('Navigation', 'create', ['id' => $parentId, 'weight' => -99]);

// If we don't flush it will not recognize newly created parent_id
CRM_Core_PseudoConstant::flush();

$optionGroupLinks = [
'Locations' => 'hrjc_location',
'Regions' => 'hrjc_region',
'Departments' => 'hrjc_department',
'Levels' => 'hrjc_level_type',
'Cost Centres' => 'cost_centres',
];

foreach ($optionGroupLinks as $itemName => $optionGroup) {
$link = 'civicrm/admin/options/' . $optionGroup . '?reset=1';
$this->createNavItem($itemName, $permission, $parentId, ['url' => $link]);
}

return TRUE;
}

/**
* Creates a navigation menu item using the API
*
* @param string $name
* @param string $permission
* @param int $parentID
* @param array $params
*
* @return array
*/
private function createNavItem($name, $permission, $parentID, $params = []) {
$params = array_merge([
'name' => $name,
'label' => ts($name),
'permission' => $permission,
'parent_id' => $parentID,
'is_active' => 1,
], $params);

$existing = civicrm_api3('Navigation', 'get', $params);

if ($existing['count'] > 0) {
return array_shift($existing['values']);
}

return civicrm_api3('Navigation', 'create', $params);
}

/**
* Creates new Option Group for Cost Centres
*/
Expand Down
4 changes: 2 additions & 2 deletions com.civicrm.hrjobroles/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<author>Compucorp Ltd</author>
<email>info@compucorp.co.uk</email>
</maintainer>
<releaseDate>2018-03-26</releaseDate>
<version>1.7.5</version>
<releaseDate>2018-04-30</releaseDate>
<version>1.7.6</version>
<develStage>stable</develStage>
<compatibility>
<ver>4.7</ver>
Expand Down
4 changes: 2 additions & 2 deletions com.civicrm.hrjobroles/js/dist/job-roles.min.js

Large diffs are not rendered by default.

0 comments on commit 814af4c

Please sign in to comment.