Skip to content

Commit 197bbbf

Browse files
authored
MRJP-6 Added kosli attest jira issues list action (#9)
* MRJP-6 Added Jira issue list custom attestation type * Added kosli attest jira issues list action
1 parent d324750 commit 197bbbf

File tree

5 files changed

+93
-25
lines changed

5 files changed

+93
-25
lines changed

.github/actions/common/lib-kosli.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ function get_oldest_commit_sha
4242
echo "$envJson" | jq -r '[.[] | .flows[]] | sort_by(.git_commit_info.timestamp) | .[0].git_commit_info.sha1'
4343
}
4444

45+
function get_commits_between_tags
46+
{
47+
local -r oldTag=$1; shift
48+
local -r newTag=$1; shift
49+
git log --format="%H" --reverse ${oldTag}..${newTag}
50+
}
4551

4652
function get_commits_between_staging_and_prod
4753
{
@@ -98,3 +104,15 @@ function get_issue_keys_between_staging_and_prod
98104
issueKeys=$(get_all_jira_issue_keys_for_commits ${flowName} "${commits}")
99105
echo ${issueKeys} | tr ' ' '\n' | sort -u | tr '\n' ' '
100106
}
107+
108+
function get_issue_keys_between_commits
109+
{
110+
local -r oldCommit=$1; shift
111+
local -r newCommit=$1; shift
112+
local -r flowName=$1; shift
113+
114+
commits=$(get_commits_between_tags ${oldCommit} ${newCommit})
115+
debug_log "Commits between ${oldCommit} ${newCommit}:\n${commits}"
116+
issueKeys=$(get_all_jira_issue_keys_for_commits ${flowName} "${commits}")
117+
echo ${issueKeys} | tr ' ' '\n' | sort -u | tr '\n' ' '
118+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Kosli Attest Jira Issue List
2+
3+
# Attest a list of jira issues referred between two git commits
4+
5+
inputs:
6+
# The Following environment variables must be set in your GitHub action
7+
# before using this composite
8+
# env:
9+
# KOSLI_ORG: kosli
10+
# KOSLI_FLOW: your-flow-name
11+
# KOSLI_TRAIL: your-trail-name (often release ID)
12+
# KOSLI_API_TOKEN: "${{ secrets.KOSLI_API_TOKEN }}"
13+
# KOSLI_CLI_VERSION: 2.11.11
14+
kosli-source-flow:
15+
description: "Flow where Jira Issues are recorded"
16+
old-commit:
17+
description: "Oldest commit (will not be included)"
18+
required: true
19+
new-commit:
20+
description: "Newest commit"
21+
required: true
22+
23+
runs:
24+
using: "composite"
25+
steps:
26+
- name: Setup Kosli cli
27+
uses: kosli-dev/setup-cli-action@v2
28+
with:
29+
version:
30+
${{ env.KOSLI_CLI_VERSION }}
31+
32+
- name: Attest Jira issue list
33+
shell: bash
34+
run: |
35+
source ${GITHUB_ACTION_PATH}/../common/lib-kosli.sh
36+
ISSUES=$(get_issue_keys_between_commits \
37+
${{ inputs.old-commit }} ${{ inputs.new-commit }} \
38+
${{ inputs.kosli-source-flow }})
39+
echo ${ISSUES} | jq -R 'split(" ")' > /tmp/jira-issues.json
40+
41+
kosli attest custom \
42+
--type=jira-issues-list \
43+
--name jira-issues \
44+
--attestation-data /tmp/jira-issues.json \
45+
--annotate "JiraIssues=${ISSUES}"
46+
47+
echo "Jira issues: ${ISSUES}" >> $GITHUB_STEP_SUMMARY

.github/workflows/setup-kosli.yml

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -51,33 +51,13 @@ jobs:
5151
# --template-file kosli-flow-templates/release-template.yml
5252

5353
### Custom attestation types ###
54-
# - name: Create approval-jira attestation type
55-
# run:
56-
# kosli create attestation-type approval-jira
57-
# --description "Approval from Jira. Must have at least 1 approver and all approvers must have APPROVED it"
58-
# --schema custom-attestation-types/approval-jira-schema.json
59-
# --jq '(.approvers | length) > 0'
60-
# --jq '[.approvers[].status == "APPROVED"] | all'
61-
#
62-
# - name: Create running-sw attestation type
63-
# run:
64-
# kosli create attestation-type running-sw
65-
# --description "List of running software in an environment"
66-
# --schema custom-attestation-types/running-sw-schema.json
54+
- name: Create running-sw attestation type
55+
run:
56+
kosli create attestation-type jira-issues-list
57+
--description "List of Jira issues"
58+
--schema custom-attestation-types/jira-issues-list-schema.json
6759

6860
### environments ###
69-
# - name: Create dev env
70-
# run:
71-
# kosli create environment ${{ env.KOSLI_ENV_DEV }}
72-
# --description "A simulated development environment"
73-
# --type server
74-
#
75-
# - name: Create staging env
76-
# run:
77-
# kosli create environment ${{ env.KOSLI_ENV_STAGING }}
78-
# --description "A simulated staging environment"
79-
# --type server
80-
8161
- name: Create prod env
8262
run:
8363
kosli create environment ${{ env.KOSLI_ENV_PROD }}

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
SHELL := bash
2+
3+
report_all_envs:
4+
gh workflow run simulate-environment-reporting-prod.yml --ref main
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"title": "JIRA Issues List",
4+
"description": "A list of JIRA issue keys",
5+
"type": "array",
6+
"items": {
7+
"type": "string",
8+
"pattern": "^[A-Z]+-[0-9]+$",
9+
"description": "JIRA issue key in format PROJECT-NUMBER (e.g., MRJP-4)"
10+
},
11+
"minItems": 0,
12+
"uniqueItems": true,
13+
"examples": [
14+
[],
15+
["MRJP-4"],
16+
["MRJP-4", "MRJP-5"],
17+
["ABC-123", "XYZ-456", "TEST-1"]
18+
]
19+
}

0 commit comments

Comments
 (0)