-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjenkins.sh
67 lines (58 loc) · 1.89 KB
/
jenkins.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash -x
last_post=${WORKSPACE}/timestamp
projects=${WORKSPACE}/projects
test -d $projects || mkdir -pv $projects
repositories=()
arguments=()
# Indicates if we should only display messages we haven't seen before.
show_unread_only=1
function fetch_all_projects() {
# Ensure all of the repositories have been cloned to our Project workspace.
for repo in $@; do
project_dir="${projects}/$(basename $repo)"
test -d $project_dir ||
git clone -b master --single-branch ${stash_clone_uri}/${repo}.git ${project_dir}
done
# Pull in the latest changes from all project repositories.
find $projects -mindepth 1 -maxdepth 1 -type d -exec git --git-dir={}/.git --work-tree={} pull origin master \;
return $?
}
function add_repository() {
local repository="${1//.git}"
echo "$repository" | grep '/' -q || {
echo "Repositories must include project: \${PROJECT_NAME}/${repository}";
return 1;
}
repositories+=("$repository");
return 0;
}
function add_repositories() {
for repo in ${1//,/ }; do
add_repository "$repo"
done
}
function get_projects() {
local project_args=''
for repo in ${repositories[@]}; do
project_args+="$(basename $repo),"
done
echo ${project_args%,}
}
function get_security_advisory_notices() {
[[ "$show_unread_only" == "0" && -f $last_post ]] && rm $last_post
# Ensure all composer dependencies are install
if [ ! -d ${WORKSPACE}/vendor ] && [ -f ${WORKSPACE}/composer.json ]; then
composer install
fi
php $WORKSPACE/sa-bot.php --project-directory $projects --last-reported-log $last_post --projects $(get_projects) $@
}
while (( $# )); do
case "$1" in
--repos=*) add_repositories ${1#*=}; shift;;
--repo*) add_repositories "$2"; shift 2;;
--unread-only) show_unread_only="$2"; shift 2;;
*) arguments+=("$1"); shift;;
esac
done
fetch_all_projects "${repositories[@]}" && get_security_advisory_notices "${arguments[@]}"
exit $?