Skip to content

Commit 26fb4a9

Browse files
authored
Added support for Jira project key with lower case and underscore (#492)
1 parent 12a92d6 commit 26fb4a9

File tree

5 files changed

+34
-7
lines changed

5 files changed

+34
-7
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ docs.kosli.com/content/client_reference/kosli*
1818
docs.kosli.com/public/
1919
docs.kosli.com/.netlify
2020
*.tar.gz
21+
/.idea
2122
# keep it uncommented on main
2223
docs.kosli.com/assets/metadata.json
2324
tmp/

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,17 @@ ensure_network:
6969
ensure_gotestsum:
7070
@go install gotest.tools/gotestsum@latest
7171

72+
clear_local_image_ref:
73+
rm /tmp/server-image.txt
74+
7275
test_setup: ensure_gotestsum
7376
# cat and exit if error
74-
./hack/get-server-image.sh > /tmp/server-image.txt || (cat /tmp/server-image.txt && exit 1)
77+
@test -f /tmp/server-image.txt || ./hack/get-server-image.sh /tmp/server-image.txt
7578
export KOSLI_SERVER_IMAGE=$$(cat /tmp/server-image.txt) && ./bin/reset-or-start-server.sh
7679

7780
test_setup_restart_server: ensure_gotestsum
7881
# cat and exit if error
79-
./hack/get-server-image.sh > /tmp/server-image.txt || (cat /tmp/server-image.txt && exit 1)
82+
@test -f /tmp/server-image.txt || ./hack/get-server-image.sh /tmp/server-image.txt
8083
export KOSLI_SERVER_IMAGE=$$(cat /tmp/server-image.txt) && ./bin/reset-or-start-server.sh force
8184

8285
test_integration: deps vet ensure_network test_setup ## Run tests except the too slow ones

cmd/kosli/attestJira.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,10 @@ func (o *attestJiraOptions) run(args []string) error {
329329
}
330330

331331
func (o *attestJiraOptions) validateJiraProjectKeys() error {
332-
matchesJiraProjectKeys, err := regexp.Compile("^[A-Z][A-Z0-9]{1,9}$")
332+
// According to Jira documentation https://confluence.atlassian.com/adminjiraserver/changing-the-project-key-format-938847081.html
333+
// the Jira project key has to start with a capital letter and can then have capital letters numbers and underscore.
334+
// But Jira itself will accept lower case letters when searching a repository for matching branches and commits
335+
matchesJiraProjectKeys, err := regexp.Compile("^[A-Za-z][A-Za-z0-9_]{1,9}$")
333336
if err != nil {
334337
return err
335338
}

cmd/kosli/attestJira_test.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,15 +248,28 @@ func (suite *AttestJiraCommandTestSuite) TestAttestJiraCmd() {
248248
commitMessage: "EX-1 test commit",
249249
},
250250
},
251+
{
252+
name: "can specify lower case and underscore jira project key",
253+
cmd: fmt.Sprintf(`attest jira --name bar
254+
--jira-base-url https://kosli-test.atlassian.net --jira-username [email protected]
255+
--jira-project-key low
256+
--jira-project-key A99
257+
--jira-project-key A_99
258+
--repo-root %s %s`, suite.tmpDir, suite.defaultKosliArguments),
259+
golden: "jira attestation 'bar' is reported to trail: test-123\n",
260+
additionalConfig: jiraTestsAdditionalConfig{
261+
commitMessage: "low-1 test commit",
262+
},
263+
},
251264
{
252265
wantError: true,
253266
name: "fails with an invalid Jira project key specified",
254-
cmd: fmt.Sprintf(`attest jira --name bar
267+
cmd: fmt.Sprintf(`attest jira --name bar
255268
--jira-base-url https://kosli-test.atlassian.net --jira-username [email protected]
256-
--jira-project-key ex
257269
--jira-project-key 1AB
270+
--jira-project-key AB-44
258271
--repo-root %s %s`, suite.tmpDir, suite.defaultKosliArguments),
259-
golden: "Error: Invalid Jira project keys: ex, 1AB\n",
272+
golden: "Error: Invalid Jira project keys: 1AB, AB-44\n",
260273
additionalConfig: jiraTestsAdditionalConfig{
261274
commitMessage: "EX-1 test commit",
262275
},

hack/get-server-image.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
#!/bin/bash
22
set -uo pipefail
33

4+
if [ $# -lt 1 ]; then
5+
echo "Output result file is missing" >&2
6+
exit 1
7+
fi
8+
9+
OUTPUT_FILE=$1; shift
10+
411
# Check that jq is installed
512
if ! command -v jq &> /dev/null; then
613
echo "❌ Error: 'jq' is not installed. Please install it:" >&2
@@ -29,4 +36,4 @@ echo "$json" | jq -r '
2936
| select(.name | test("merkely:"))
3037
| select(.annotation.type != "exited")
3138
| "\(.name | sub(":.*"; ""))@sha256:\(.fingerprint)"
32-
'
39+
' > ${OUTPUT_FILE}

0 commit comments

Comments
 (0)