Skip to content

Commit

Permalink
Label creation automation, add logic for more than 100 labels
Browse files Browse the repository at this point in the history
Signed-off-by: Prudhvi Godithi <pgodithi@amazon.com>
  • Loading branch information
prudhvigodithi committed Jun 23, 2023
1 parent df1dfdd commit 844231f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 39 deletions.
42 changes: 21 additions & 21 deletions .github/workflows/os-increment-plugin-versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -136,4 +136,4 @@ jobs:
- name: Check outputs
run: |-
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"
36 changes: 18 additions & 18 deletions .github/workflows/osd-increment-plugin-versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 844231f

Please sign in to comment.