From 7532ae7deca2cedea4b24310d47a702be0016bf5 Mon Sep 17 00:00:00 2001 From: Prudhvi Godithi Date: Thu, 22 Jun 2023 16:41:21 -0700 Subject: [PATCH] Label creation automation, add logic for more than 100 labels Signed-off-by: Prudhvi Godithi --- .../os-increment-plugin-versions.yml | 40 +++++++++---------- .../osd-increment-plugin-versions.yml | 36 ++++++++--------- 2 files changed, 38 insertions(+), 38 deletions(-) diff --git a/.github/workflows/os-increment-plugin-versions.yml b/.github/workflows/os-increment-plugin-versions.yml index 104a9a03bf..207aa41599 100644 --- a/.github/workflows/os-increment-plugin-versions.yml +++ b/.github/workflows/os-increment-plugin-versions.yml @@ -85,36 +85,36 @@ jobs: app_id: ${{ secrets.APP_ID }} private_key: ${{ secrets.APP_PRIVATE_KEY }} installation_id: 22958780 - - name: Check if label exists - id: check_label + - name: Check and Create label + id: check_create_label uses: actions/github-script@v6 with: github-token: ${{ steps.github_app_token.outputs.token }} result-encoding: string script: | - const { data: labels } = await github.rest.issues.listLabelsForRepo({ + const labelName = "v${{ env.OPENSEARCH_VERSION_NUMBER }}"; + let labelFound = false; + const label = await github.rest.issues.getLabel({ owner: context.repo.owner, repo: "${{ matrix.entry.repo }}", - per_page: 100 + name: labelName }); - const labelFound = labels.some(label => label.name === 'v${{ env.OPENSEARCH_VERSION_NUMBER }}'); + if (label) { + labelFound = true; + } else { + const randomColor = Math.floor(Math.random() * 16777215).toString(16); + const newLabel = { + owner: context.repo.owner, + repo: context.repo.repo, + name: labelName, + color: randomColor, + description: labelName + }; + await github.rest.issues.createLabel(newLabel); + labelFound = true; + } console.log(labelFound); return labelFound - - name: Create label - if: ${{ steps.check_label.outputs.result != 'true' }} - uses: actions/github-script@v6 - with: - github-token: ${{ steps.github_app_token.outputs.token }} - script: | - const randomColor = Math.floor(Math.random() * 16777215).toString(16); - const newLabel = { - owner: context.repo.owner, - repo: "${{ matrix.entry.repo }}", - name: "v${{ env.OPENSEARCH_VERSION_NUMBER }}", - color: randomColor, - description: "v${{ env.OPENSEARCH_VERSION_NUMBER }}" - }; - await github.rest.issues.createLabel(newLabel); - name: Create Pull Request id: cpr uses: peter-evans/create-pull-request@v4 diff --git a/.github/workflows/osd-increment-plugin-versions.yml b/.github/workflows/osd-increment-plugin-versions.yml index a29628a80a..6b73424e3b 100644 --- a/.github/workflows/osd-increment-plugin-versions.yml +++ b/.github/workflows/osd-increment-plugin-versions.yml @@ -109,29 +109,29 @@ jobs: github-token: ${{ steps.github_app_token.outputs.token }} result-encoding: string script: | - const { data: labels } = await github.rest.issues.listLabelsForRepo({ + const labelName = "v${{ env.DASHBOARD_VERSION }}"; + let labelFound = false; + const label = await github.rest.issues.getLabel({ owner: context.repo.owner, repo: "${{ matrix.entry.repo }}", - per_page: 100 + name: labelName }); - const labelFound = labels.some(label => label.name === 'v${{ env.DASHBOARD_VERSION }}'); + if (label) { + labelFound = true; + } else { + const randomColor = Math.floor(Math.random() * 16777215).toString(16); + const newLabel = { + owner: context.repo.owner, + repo: context.repo.repo, + name: labelName, + color: randomColor, + description: labelName + }; + await github.rest.issues.createLabel(newLabel); + labelFound = true; + } console.log(labelFound); return labelFound - - name: Create label - if: ${{ steps.check_label.outputs.result != 'true' }} - uses: actions/github-script@v6 - with: - github-token: ${{ steps.github_app_token.outputs.token }} - script: | - const randomColor = Math.floor(Math.random() * 16777215).toString(16); - const newLabel = { - owner: context.repo.owner, - repo: "${{ matrix.entry.repo }}", - name: "v${{ env.DASHBOARD_VERSION }}", - color: randomColor, - description: "v${{ env.DASHBOARD_VERSION }}" - }; - await github.rest.issues.createLabel(newLabel); - name: Create Pull Request id: cpr uses: peter-evans/create-pull-request@v5