Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document/example how to use PAC as a gate for unreferenced/wrong issue properties - using bash #126

Open
bicschneider opened this issue Mar 11, 2021 · 1 comment
Assignees

Comments

@bicschneider
Copy link

Using PAC a harvester then wrap status output etc for verdicting the report. Add a bash example

@bicschneider bicschneider self-assigned this Mar 11, 2021
@bicschneider
Copy link
Author

bicschneider commented Mar 11, 2021

#!/bin/bash

# Crash build, if any commits are found without JIRA references:
set -x
set -e
set -u

which docker
docker --version

rm -f jira.md
rm -f pac_failures.txt            && touch pac_failures.txt
rm -f pac_failure_unprocessed.txt && touch pac_failure_unprocessed.txt 
rm -f pac_verdict.txt             && touch pac_verdict.txt 

# create jira template

echo '# TESHMI Jira references
{% if tasks.jira_TESHMI.size > 0 %}{% for task in tasks.jira_TESHMI %}
## {{task.task_id}} {{task.attributes.data.fields.assignee.email}} {{task.attributes.data.fields.status.name}} {{task.attributes.data.fields.summary}}
{{task.attributes.data.fields.description}}
{% for commit in task.commits %} - {{commit.shortsha}}: {{commit.header}}{% endfor %}{% endfor %}{% endif %}

{% if tasks.unknown.size > 0 %}
# Lookup-errors
{% for task in tasks.unknown%}
## {{task.task_id}}
{% for commit in task.commits %}- {{commit.shortsha}}: {{commit.header}}{% endfor %}{% endfor %}{% endif %}

{% if tasks.unreferenced.size > 0 %}
# Unreferenced
{% for commit in tasks.unreferenced %}
 - {{commit.shortsha}}: {{commit.header}}{% endfor %}{% endif %}

{% if tasks.none.size > 0 %}
# Nones
{% for task in tasks.none %}
 - {{task.task_id}}{% endfor %}{% endif %}

## Statistics
- Total number of commits: {{pac_c_count}}
- Total number of Jira ref TESHMI commits: {{tasks.jira_TESHMI.size}}
- Total number of none referenced commits: {{tasks.none.size}}
- Total number of unknown reference commits: {{tasks.unknown.size}}
- Total number of unreferenced commits: {{tasks.unreferenced.size}}
- Referenced commits: {{pac_c_referenced}}
- Health: {{pac_health}}
' > jira_template.md

echo ":general:
  :strict: true
:templates:
  - { location: /data/jira_template.md, output: jira.md }
:task_systems:  
  -
    :name: jira
    :debug: true
    :regex:
      - { pattern: '/(TESHMI-\d+)/', label: jira_TESHMI }
    :query_string: "${JIRA_SERVER_URL}/rest/api/latest/issue/#{task_id}"
    :usr: ${JIRA_USERNAME}
    :pw: ${JIRA_PASSWORD}     
:vcs:
  :type: git
  :repo_location: '.'

" > settings_pac-jira.yml

exit_code=0
docker_exit_code="0"
pac_debug="" # " -v -v "

docker run \
     -v $(pwd | sed -e 's/mnt//'):/data \
     -v /etc/ssl/certs:/etc/ssl/certs:ro \
     --net=host \
     praqma/pac:3.x.x-latest \
     pac \
        from ${GIT_REFERENCE_MASTER} \
        --settings=/data/settings_pac-jira.yml  \
        ${pac_debug} \
        -c ${JIRA_USERNAME} ${JIRA_PASSWORD} jira \
        > pac_failures.txt \
  || docker_exit_code=$?

if  [[ $docker_exit_code -eq 7 ]]; then
  echo "The docker have exited with error: ${docker_exit_code} - it indicate the daemon is not running correctly or disk shared not working"
  exit $docker_exit_code
fi 
if [[ ! -f jira.md ]]; then
  echo "jira.md does not exist - something has gone wrong" 
  exit 255
fi
     
if  [[ $docker_exit_code -eq 0 ]]; then
  if [[ $(grep '^# Unreferenced$' jira.md) ]]; then
    echo "ERROR: We found that there are unreferenced issues" >> pac_verdict.txt
    [[ "${exit_code}" -eq 255 ]] || exit_code=10
  else
    # file was found, pattern not found - good exit
    echo "All good - All commits are referenced"
  fi
elif [[ $docker_exit_code -eq 15 ]]; then
  cat pac_failures.txt > pac_failures_unprocessed.txt
  if [[ $(grep "return code was 401" pac_failures_unprocessed.txt) ]] ; then
    exit_code=255
    echo "ERROR: PAC failed due to credentials issues.." >> pac_verdict.txt
    grep -v "return code was 401" pac_failures_unprocessed.txt > pac_failure_unprocessed.txt || true
  fi
  if [[ $(grep "return code was 404" pac_failures_unprocessed.txt) ]] ; then 
    [[ "${exit_code}" -eq 255 ]] || exit_code=10
    echo "ERROR: PAC failed due to look up of issues.." >> pac_verdict.txt
    grep -v "return code was 404" pac_failures_unprocessed.txt > pac_failure_unprocessed.txt || true
  fi
  if [[ $(cat pac_failure_unprocessed.txt | wc -l) > 0 ]]; then
   	echo "ERROR PAC reported unknown error(s)" >> pac_verdict.txt
    exit_code=255
  fi
else 
  echo "PAC failed due to unknown issues"
  exit_code=255
fi
set +x
echo 
echo "########## JIRA report ####################"
cat jira.md
echo 
echo "########## PAC verdict ####################"
cat pac_verdict.txt

echo
echo "########## PAC failures ###################"
cat pac_failure_unprocessed.txt
echo
set -x
exit ${exit_code}

@bicschneider bicschneider changed the title Document/example how to use PAC as a gate for unreferenced/wrong Jira properties - using bash Document/example how to use PAC as a gate for unreferenced/wrong issue properties - using bash Mar 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant