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 <[email protected]>
  • Loading branch information
prudhvigodithi committed Jun 23, 2023
1 parent df1dfdd commit 7532ae7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 38 deletions.
40 changes: 20 additions & 20 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 Down
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 7532ae7

Please sign in to comment.