Skip to content

Commit

Permalink
add list_issues, request_clone
Browse files Browse the repository at this point in the history
  • Loading branch information
richm committed Apr 30, 2024
1 parent ea739b8 commit ed3e8ab
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 0 deletions.
39 changes: 39 additions & 0 deletions jira_playbooks/list_issues_pb.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
- name: List issues
hosts: localhost
gather_facts: false
vars:
config_file: "{{ lookup('env', 'HOME') ~ '/.config/jira.yml' }}"
config: "{{ lookup('file', config_file) | from_yaml }}"
current: "{{ config['current'] }}"
url: "{{ config[current]['url'] }}"
token: "{{ config[current]['token'] }}"
project: "{{ config[current]['project'] }}"
component: "{{ config[current]['component'] }}"
product: "{{ config[current]['product'] }}"
pool_team: "{{ config[current]['pool_team'] }}"
itr_query_field: fixVersion
itr: "{{ lookup('env', 'ITR') if lookup('env', 'ITR') | length > 0 else 'rhel-9.4.0' }}"
status_query_field: status
module_defaults:
community.general.jira:
project: "{{ project }}"
token: "{{ token }}"
uri: "{{ url }}"
tasks:
- name: Get issues matching criteria
community.general.jira:
operation: search
jql: component = {{ component }} AND "{{ itr_query_field }}" = {{ itr }} AND "{{ status_query_field }}" = "{{ status }}"
args:
fields:
summary:
customfield_12318450: # Fixed In Build
register: issues # issues.meta.issues

- name: List issues
copy:
content: |-
{% for issue in issues.meta.issues %}
{{ issue.key }} {{ issue.fields.customfield_12318450 }} {{ issue.fields.summary }}
{% endfor %}
dest: "{{ output_file | d('issues') }}"
74 changes: 74 additions & 0 deletions jira_playbooks/request_clone_pb.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
---
- name: Use the Request Clones feature to clone a given issue
hosts: localhost
gather_facts: false
vars:
config_file: "{{ lookup('env', 'HOME') ~ '/.config/jira.yml' }}"
config: "{{ lookup('file', config_file) | from_yaml }}"
current: "{{ config['current'] }}"
url: "{{ config[current]['url'] }}"
token: "{{ config[current]['token'] }}"
project: "{{ config[current]['project'] }}"
component: "{{ config[current]['component'] }}"
product: "{{ config[current]['product'] }}"
pool_team: "{{ config[current]['pool_team'] }}"
module_defaults:
community.general.jira:
project: "{{ project }}"
token: "{{ token }}"
uri: "{{ url }}"
tasks:
- name: Set update issue key
set_fact:
update_issue_key: "{{ clone_issue_key }}"

- name: Request clone
include_tasks: tasks/update_issue.yml

- name: Get issue to clone
community.general.jira:
operation: fetch
issue: "{{ clone_issue_key }}"
register: clone_issue
until: clone_issue.meta.fields.issuelinks | selectattr('type.inward', 'match', 'is cloned by') | length > 0

- name: Debug
debug:
msg: links {{ clone_issue.meta.fields.issuelinks | selectattr('type.inward', 'match', 'is cloned by') | list | to_nice_json }}

- name: Wait until new issue points to cloned issue
community.general.jira:
operation: fetch
issue: "{{ new_issue_key }}"
register: new_issue
until: new_issue.meta.fields.issuelinks | selectattr("outwardIssue.key", "match", clone_issue_key) | length > 0
vars:
new_issue_key: "{{ clone_issue.meta.fields.issuelinks | selectattr('type.inward', 'match', 'is cloned by') |
selectattr('inwardIssue', 'defined') | map(attribute='inwardIssue.key') | first }}"

# many of the fields are copied by the request clone process
# other fields are updated accordingly e.g. fixVersion is set correctly
- name: Set vars for creating the clone
set_fact:
doc_text: "{{ clone_issue.meta.fields.customfield_12317313 | d('') }}"
doc_text_type: "{{ clone_issue.meta.fields.customfield_12320850.value | d('') }}"
docs_impact: "{{ clone_issue.meta.fields.customfield_12324040.value | d('') }}"
dev_ack: "{{ 'Dev ack' if clone_issue.meta.fields.customfield_12317366 |
selectattr('value', 'eq', 'Dev ack') | length > 0 else '' }}"
qa_ack: "{{ 'QE ack' if clone_issue.meta.fields.customfield_12317366 |
selectattr('value', 'eq', 'QE ack') | length > 0 else '' }}"
itm: "{{ clone_issue.meta.fields.customfield_12321040.value | d('') | string }}"
dtm: "{{ clone_issue.meta.fields.customfield_12318141.value | d('') | string }}"
sprint: "{{ __sprint_id | string }}"
status: "{{ clone_issue.meta.fields.status.name }}"
story_points: "{{ '%f' | format(clone_issue.meta.fields.customfield_12310243 | d(0.0)) | string }}"
preliminary_testing: "{{ clone_issue.meta.fields.customfield_12321540.value | d('') }}"
update_issue_key: "{{ new_issue.meta.key }}"
vars:
__pat: >-
^.*\[id=(\d+),.*$
__sprint_id: "{{ clone_issue.meta.fields.customfield_12310940 | d(['']) |
map('regex_replace', __pat, '\\1') | first }}"

- name: Update new issue
include_tasks: tasks/update_issue.yml
21 changes: 21 additions & 0 deletions jira_playbooks/tasks/update_issue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@
docs_impact: # choice of No, Yes
fieldname: customfield_12324040
updatetype: value_dict
request_clone_version: # e.g. "RHEL 10"
fieldname: customfield_12323242
updatetype: value_dict
fixed_in_build:
fieldname: customfield_12318450
updatetype: string
sprint:
fieldname: customfield_12310940
updatetype: int
story_points:
fieldname: customfield_12310243
updatetype: float
preliminary_testing:
fieldname: customfield_12321540
updatetype: value_dict
__roles_list: "{{ [] if labels | d([]) | length > 0
else roles | d('') | split(',') | sort }}"
__labels: "{{ labels if labels | d([]) | length > 0
Expand Down Expand Up @@ -76,6 +91,12 @@
{% elif __field_map[var]["updatetype"] == "list" %}
{% set item = val %}
{% set _ = rv.setdefault(__field_map[var]["fieldname"], []).append(item) %}
{% elif __field_map[var]["updatetype"] == "float" %}
{% set item = val | float %}
{% set _ = rv.update({__field_map[var]["fieldname"]: item}) %}
{% elif __field_map[var]["updatetype"] == "int" %}
{% set item = val | int %}
{% set _ = rv.update({__field_map[var]["fieldname"]: item}) %}
{% endif %}
{% endif %}
{% endfor %}
Expand Down
21 changes: 21 additions & 0 deletions manage-issues.sh
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,20 @@ clone_and_link_issue() {
ansible-playbook -vv -e clone_issue_key="$1" -e clone_version="$2" jira_playbooks/clone_and_link_issue_pb.yml
}

request_clone_issue() {
# version is something like e.g. "RHEL 10"
# field to set in clone - must be listed in __field_map in update_issue.yml
local cmdline
cmdline=(-vv -e clone_issue_key="$1" -e request_clone_version="'$2'")
shift; shift
while [ -n "${1:-}" ] && [ -n "${2:-}" ]; do
# shellcheck disable=SC2191
cmdline+=(-e "$1"="$2"); shift; shift
done
ansible-playbook "${cmdline[@]}" jira_playbooks/request_clone_pb.yml
}


rpm_release() {
ansible-playbook -vv -e rpm_version="$1" jira_playbooks/rpm_release_pb.yml
}
Expand Down Expand Up @@ -163,4 +177,11 @@ dump_issue() {
ansible-playbook -vv -e issue_key="$1" -e issue_file="${2:-"$1.json"}" jira_playbooks/dump_issue.yml
}

list_issues() {
local output_file
output_file="$(pwd)/issues"
ansible-playbook -vv -e status="'$1'" -e output_file="$output_file" jira_playbooks/list_issues_pb.yml
cat "$output_file"
}

"$@"

0 comments on commit ed3e8ab

Please sign in to comment.