Skip to content

Commit 18b8d21

Browse files
Make commit pragma matching case insenstive (#10)
Signed-off-by: Brian J. Murrell <brian.murrell@intel.com>
1 parent 390e072 commit 18b8d21

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

Jenkinsfile

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,25 @@ Sleep-seconds: 2'''
5656
env.COMMIT_MESSAGE = 'A commit message with a "double quote"'
5757
// just make sure this doesn't trip an error due to the double
5858
// quotes
59-
println(commitPragmaTrusted(pragma: 'Foo-bar:',
59+
assert(commitPragmaTrusted(pragma: 'Foo-bar',
6060
def_val: '1') == "1")
6161
}
6262
} // steps
6363
} //stage ('env.COMMIT_MESSAGE pragma test')
64+
stage ('env.COMMIT_MESSAGE case insensitivity test') {
65+
steps {
66+
script {
67+
env.COMMIT_MESSAGE = '''A commit message
68+
69+
Set in env.COMMIT_MESSAGE
70+
71+
Sleep-seconds: 2'''
72+
// just make sure this doesn't trip an error due to the double
73+
// quotes
74+
assert(commitPragmaTrusted('sleep-seconds', '1') == "2")
75+
}
76+
} // steps
77+
} //stage ('env.COMMIT_MESSAGE pragma test')
6478
} // stage ('Test')
6579
post {
6680
success {

vars/commitPragmaTrusted.groovy

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,19 @@
1010
* config['def_val'] Value to return if not found
1111
*/
1212
def call(Map config = [:]) {
13+
// convert the map for compat
14+
return commitPragmaTrusted(config['pragma'], config['def_val'])
15+
}
16+
17+
def call(String name, String def_val = null) {
18+
/**
19+
* @param name Pragma to get the value of
20+
* @param def_val Value to return if not found
21+
*/
1322

1423
def def_value = ''
15-
if (config['def_val']) {
16-
def_value = config['def_val']
24+
if (def_val) {
25+
def_value = def_val
1726
}
1827

1928
String commit_message=""
@@ -36,8 +45,8 @@ def call(Map config = [:]) {
3645
returnStdout: true).trim()
3746
}
3847
return sh(script: 'b=$(echo "' + commit_message.replaceAll('"', '\\\\"') +
39-
'''" | sed -ne 's/^''' + config['pragma'] +
40-
''': *\\(.*\\)/\\1/p')
48+
'''" | sed -ne 's/^''' + name +
49+
''': *\\(.*\\)/\\1/Ip')
4150
if [ -n "$b" ]; then
4251
echo "$b"
4352
else

0 commit comments

Comments
 (0)