From 1a3df294d010a2ef46f079ff8bd8c85a2a847464 Mon Sep 17 00:00:00 2001 From: Madhura Bhave Date: Mon, 6 Apr 2020 19:05:26 -0700 Subject: [PATCH] Prevent duplication of issues created by CI automation This is done by checking for existing issues only in the milestone corresponding to the current branch. For issues, the milestone is assigned at the time of issue creation. For PRs, since the branch is different the milestone can be derived from that while triaging the issue. Closes gh-20680 --- ci/pipeline.yml | 4 ++++ ci/scripts/detect-docker-updates.sh | 4 +++- ci/scripts/detect-jdk-updates.sh | 5 +++-- ci/scripts/detect-ubuntu-image-updates.sh | 5 +++-- ci/tasks/detect-docker-updates.yml | 1 + ci/tasks/detect-jdk-updates.yml | 1 + ci/tasks/detect-ubuntu-image-updates.yml | 1 + 7 files changed, 16 insertions(+), 5 deletions(-) diff --git a/ci/pipeline.yml b/ci/pipeline.yml index fc48e2d7e3..581d3c4add 100644 --- a/ci/pipeline.yml +++ b/ci/pipeline.yml @@ -161,6 +161,7 @@ jobs: GITHUB_PASSWORD: ((github-password)) GITHUB_USERNAME: ((github-username)) JDK_VERSION: java8 + MILESTONE: ((branch)) image: spring-boot-ci-image - task: detect-jdk11-update file: git-repo/ci/tasks/detect-jdk-updates.yml @@ -170,6 +171,7 @@ jobs: GITHUB_PASSWORD: ((github-password)) GITHUB_USERNAME: ((github-username)) JDK_VERSION: java11 + MILESTONE: ((branch)) image: spring-boot-ci-image - name: detect-ubuntu-image-updates plan: @@ -185,6 +187,7 @@ jobs: GITHUB_ORGANIZATION: spring-projects GITHUB_PASSWORD: ((github-password)) GITHUB_USERNAME: ((github-username)) + MILESTONE: ((branch)) image: spring-boot-ci-image - name: detect-docker-updates plan: @@ -199,6 +202,7 @@ jobs: params: GITHUB_REPO: spring-boot GITHUB_ORGANIZATION: spring-projects + MILESTONE: ((branch)) image: spring-boot-ci-image - put: git-repo-ci-docker params: diff --git a/ci/scripts/detect-docker-updates.sh b/ci/scripts/detect-docker-updates.sh index b76feba0c6..529b6242c0 100755 --- a/ci/scripts/detect-docker-updates.sh +++ b/ci/scripts/detect-docker-updates.sh @@ -3,7 +3,9 @@ latest_version=$(curl -I -s https://github.com/docker/docker-ce/releases/latest | grep "location:" | awk '{n=split($0, parts, "/"); print substr(parts[n],2);}' | awk '{$1=$1;print}' | tr -d '\r' | tr -d '\n' ) title_prefix="Upgrade CI to Docker" -existing_upgrade_issues=$( curl -s https://api.github.com/repos/spring-projects/spring-boot/issues\?labels\=type:%20task\&state\=open\&creator\=spring-buildmaster | jq -c --arg TITLE_PREFIX "$title_prefix" '.[] | select(.pull_request != null) | select(.title | startswith($TITLE_PREFIX))' ) +milestone_number=$( curl -s https://api.github.com/repos/${GITHUB_ORGANIZATION}/${GITHUB_REPO}/milestones\?state\=open | jq -c --arg MILESTONE "$MILESTONE" '.[] | select(.title==$MILESTONE)' | jq -r '.number') + +existing_upgrade_issues=$( curl -s https://api.github.com/repos/${GITHUB_ORGANIZATION}/${GITHUB_REPO}/issues\?labels\=type:%20task\&state\=open\&creator\=spring-buildmaster\&milestone\=${milestone_number} | jq -c --arg TITLE_PREFIX "$title_prefix" '.[] | select(.pull_request != null) | select(.title | startswith($TITLE_PREFIX))' ) if [[ ${existing_upgrade_issues} = "" ]]; then git clone git-repo git-repo-updated > /dev/null diff --git a/ci/scripts/detect-jdk-updates.sh b/ci/scripts/detect-jdk-updates.sh index bace1535fe..c006839662 100755 --- a/ci/scripts/detect-jdk-updates.sh +++ b/ci/scripts/detect-jdk-updates.sh @@ -24,7 +24,8 @@ if [[ $current = $latest ]]; then exit 0; fi -existing_tasks=$( curl -s https://api.github.com/repos/${GITHUB_ORGANIZATION}/${GITHUB_REPO}/issues\?labels\=type:%20task\&state\=open\&creator\=spring-buildmaster ) +milestone_number=$( curl -s https://api.github.com/repos/${GITHUB_ORGANIZATION}/${GITHUB_REPO}/milestones\?state\=open | jq -c --arg MILESTONE "$MILESTONE" '.[] | select(.title==$MILESTONE)' | jq -r '.number') +existing_tasks=$( curl -s https://api.github.com/repos/${GITHUB_ORGANIZATION}/${GITHUB_REPO}/issues\?labels\=type:%20task\&state\=open\&creator\=spring-buildmaster\&milestone\=${milestone_number} ) existing_jdk_issues=$( echo "$existing_tasks" | jq -c --arg TITLE "$ISSUE_TITLE" '.[] | select(.title==$TITLE)' ) if [[ ${existing_jdk_issues} = "" ]]; then @@ -32,7 +33,7 @@ if [[ ${existing_jdk_issues} = "" ]]; then -s \ -u ${GITHUB_USERNAME}:${GITHUB_PASSWORD} \ -H "Content-type:application/json" \ - -d "{\"title\":\"${ISSUE_TITLE}\",\"body\": \"${latest}\",\"labels\":[\"status: waiting-for-triage\",\"type: task\"]}" \ + -d "{\"title\":\"${ISSUE_TITLE}\",\"milestone\":\"${milestone_number}\",\"body\": \"${latest}\",\"labels\":[\"status: waiting-for-triage\",\"type: task\"]}" \ -f \ -X \ POST "https://api.github.com/repos/${GITHUB_ORGANIZATION}/${GITHUB_REPO}/issues" > /dev/null || { echo "Failed to create issue" >&2; exit 1; } diff --git a/ci/scripts/detect-ubuntu-image-updates.sh b/ci/scripts/detect-ubuntu-image-updates.sh index a8e58bd75f..7973090824 100755 --- a/ci/scripts/detect-ubuntu-image-updates.sh +++ b/ci/scripts/detect-ubuntu-image-updates.sh @@ -11,7 +11,8 @@ if [[ $current = $latest ]]; then exit 0; fi -existing_tasks=$( curl -s https://api.github.com/repos/${GITHUB_ORGANIZATION}/${GITHUB_REPO}/issues\?labels\=type:%20task\&state\=open\&creator\=spring-buildmaster ) +milestone_number=$( curl -s https://api.github.com/repos/${GITHUB_ORGANIZATION}/${GITHUB_REPO}/milestones\?state\=open | jq -c --arg MILESTONE "$MILESTONE" '.[] | select(.title==$MILESTONE)' | jq -r '.number') +existing_tasks=$( curl -s https://api.github.com/repos/${GITHUB_ORGANIZATION}/${GITHUB_REPO}/issues\?labels\=type:%20task\&state\=open\&creator\=spring-buildmaster\&milestone\=${milestone_number} ) existing_upgrade_issues=$( echo "$existing_tasks" | jq -c --arg TITLE "$ISSUE_TITLE" '.[] | select(.title==$TITLE)' ) if [[ ${existing_upgrade_issues} = "" ]]; then @@ -19,7 +20,7 @@ if [[ ${existing_upgrade_issues} = "" ]]; then -s \ -u ${GITHUB_USERNAME}:${GITHUB_PASSWORD} \ -H "Content-type:application/json" \ - -d "{\"title\":\"${ISSUE_TITLE}\",\"body\": \"Upgrade to ubuntu:${ubuntu}-${latest}\",\"labels\":[\"status: waiting-for-triage\",\"type: task\"]}" \ + -d "{\"title\":\"${ISSUE_TITLE}\",\"milestone\":\"${milestone_number}\",\"body\": \"Upgrade to ubuntu:${ubuntu}-${latest}\",\"labels\":[\"status: waiting-for-triage\",\"type: task\"]}" \ -f \ -X \ POST "https://api.github.com/repos/${GITHUB_ORGANIZATION}/${GITHUB_REPO}/issues" > /dev/null || { echo "Failed to create issue" >&2; exit 1; } diff --git a/ci/tasks/detect-docker-updates.yml b/ci/tasks/detect-docker-updates.yml index 5c0f606f55..92817b8371 100644 --- a/ci/tasks/detect-docker-updates.yml +++ b/ci/tasks/detect-docker-updates.yml @@ -9,5 +9,6 @@ outputs: params: GITHUB_REPO: GITHUB_ORGANIZATION: + MILESTONE: run: path: git-repo/ci/scripts/detect-docker-updates.sh diff --git a/ci/tasks/detect-jdk-updates.yml b/ci/tasks/detect-jdk-updates.yml index 3b0615d7e6..f0e7ce0b26 100644 --- a/ci/tasks/detect-jdk-updates.yml +++ b/ci/tasks/detect-jdk-updates.yml @@ -8,5 +8,6 @@ params: GITHUB_PASSWORD: GITHUB_USERNAME: JDK_VERSION: + MILESTONE: run: path: git-repo/ci/scripts/detect-jdk-updates.sh diff --git a/ci/tasks/detect-ubuntu-image-updates.yml b/ci/tasks/detect-ubuntu-image-updates.yml index dd3fb066b1..7e5a401af8 100644 --- a/ci/tasks/detect-ubuntu-image-updates.yml +++ b/ci/tasks/detect-ubuntu-image-updates.yml @@ -7,5 +7,6 @@ params: GITHUB_ORGANIZATION: GITHUB_PASSWORD: GITHUB_USERNAME: + MILESTONE: run: path: git-repo/ci/scripts/detect-ubuntu-image-updates.sh