changefiles.sh 980 B

123456789101112131415161718192021
  1. #!/bin/bash
  2. #set -x
  3. suffix=${1}
  4. url="${CI_SERVER_URL}/api/v4/projects/${CI_PROJECT_ID}/repository/commits/${CI_COMMIT_SHA}/merge_requests?private_token=${CI_PRIVATE_TOKEN}"
  5. json=$(curl -s ${url})
  6. if [[ "$json" != "[]" && "$json" != "" ]]; then
  7. target_branch=$(echo ${json} | jq -r '.[0].target_branch')
  8. source_branch=$(echo ${json} | jq -r '.[0].source_branch')
  9. files=$(git diff origin/${target_branch}...origin/${source_branch} --name-only --diff-filter=ACM | grep -E -i "${suffix}")
  10. else
  11. # url="${CI_SERVER_URL}/api/v4/projects/${CI_PROJECT_ID}/pipelines?private_token=${CI_PRIVATE_TOKEN}&status=success&ref=${CI_COMMIT_REF_NAME}"
  12. # commit=$(curl -s ${url} | jq -r 'first(.[] | .sha)')
  13. ## echo "Last green commit is '${commit}'."
  14. # files=$(git diff ${commit} --name-only --diff-filter=ACM | grep -E "${suffix}")
  15. files=$(git diff origin/master...origin/${CI_COMMIT_REF_NAME} --name-only --diff-filter=ACM | grep -E -i "${suffix}")
  16. fi
  17. echo -e "${files}"