Skip to content

Commit 4e64247

Browse files
committed
codereview: use composite action, actions/download-artifact, and add comments
1 parent 440651d commit 4e64247

File tree

5 files changed

+46
-44
lines changed

5 files changed

+46
-44
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
name: Install dda
3+
description: Installs the defined version of dda
4+
inputs:
5+
pr-number:
6+
description: The PR number
7+
required: true
8+
github-token:
9+
description: Github token to write label in the PR
10+
required: true
11+
12+
runs:
13+
using: composite
14+
steps:
15+
- name: Assign team label
16+
run: dda inv -- -e github.assign-team-label --pr-id="${{ inputs.pr-number }}"
17+
env:
18+
GITHUB_TOKEN: ${{ inputs.github-token }}
19+
- name: Save PR number for workflow_run
20+
run: echo "${{ inputs.pr-number }}" > pr_number.txt
21+
- name: Upload PR number artifact
22+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
23+
with:
24+
name: pr_number
25+
path: pr_number.txt

.github/workflows/add-label-community-pr.yml

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ name: Add labels to community PRs
44
on:
55
# run in the context of the base branch, so that it still works in PR from forks
66
pull_request_target:
7-
types: [opened, synchronize]
7+
types: [opened, synchronize, reopened]
88

99
permissions: {}
1010

@@ -38,13 +38,7 @@ jobs:
3838
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3939
SLACK_DATADOG_AGENT_BOT_TOKEN: ${{ secrets.SLACK_DATADOG_AGENT_BOT_TOKEN }}
4040
- name: Assign team label
41-
run: dda inv -- -e github.assign-team-label --pr-id="${{ github.event.pull_request.number }}"
42-
env:
43-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
44-
- name: Save PR number for workflow_run
45-
run: echo "${{ github.event.pull_request.number }}" > pr_number.txt
46-
- name: Upload PR number artifact
47-
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
41+
uses: ./.github/actions/assign-team-label
4842
with:
49-
name: pr_number
50-
path: pr_number.txt
43+
pr-number: ${{ github.event.pull_request.number }}
44+
github_token: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/add-label-pr.yml

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ jobs:
3131
uses: ./.github/actions/install-dda
3232
with:
3333
features: legacy-tasks
34-
- name: Auto assign team label
35-
run: dda inv -- -e github.assign-team-label --pr-id="${{ github.event.pull_request.number }}"
36-
env:
37-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3834
- name: Add the internal label
3935
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7.1.0
4036
with:
@@ -46,10 +42,8 @@ jobs:
4642
issue_number: ${{ github.event.pull_request.number }},
4743
labels: ['internal']
4844
});
49-
- name: Save PR number for workflow_run
50-
run: echo "${{ github.event.pull_request.number }}" > pr_number.txt
51-
- name: Upload PR number artifact
52-
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
45+
- name: Assign team label
46+
uses: ./.github/actions/assign-team-label
5347
with:
54-
name: pr_number
55-
path: pr_number.txt
48+
pr-number: ${{ github.event.pull_request.number }}
49+
github_token: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/label-analysis.yml

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ on:
88
- main
99
- "[0-9]+.[0-9]+.x"
1010
workflow_run:
11+
# We need to run the label analysis as workflow_run because the label addition will not trigger it.
12+
# See documentation https://docs.github.com/en/actions/how-tos/write-workflows/choose-when-workflows-run/trigger-a-workflow
1113
workflows: ["Add labels to PR", "Add labels to community PRs"]
1214
types: [completed]
1315

@@ -27,32 +29,13 @@ jobs:
2729
HEAD_REF: ${{ steps.context.outputs.head_ref }}
2830
IS_FORK: ${{ steps.context.outputs.is_fork }}
2931
steps:
30-
- name: Get PR number from artifact (workflow_run)
32+
- name: Download PR number artifact
3133
if: github.event_name == 'workflow_run'
32-
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7.1.0
34+
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
3335
with:
34-
script: |
35-
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
36-
owner: context.repo.owner,
37-
repo: context.repo.repo,
38-
run_id: ${{ github.event.workflow_run.id }},
39-
});
40-
const matchArtifact = artifacts.data.artifacts.find(artifact => artifact.name === 'pr_number');
41-
if (!matchArtifact) {
42-
core.setFailed('No pr_number artifact found');
43-
return;
44-
}
45-
const download = await github.rest.actions.downloadArtifact({
46-
owner: context.repo.owner,
47-
repo: context.repo.repo,
48-
artifact_id: matchArtifact.id,
49-
archive_format: 'zip',
50-
});
51-
const fs = require('fs');
52-
fs.writeFileSync('${{ github.workspace }}/pr_number.zip', Buffer.from(download.data));
53-
- name: Extract PR number artifact
54-
if: github.event_name == 'workflow_run'
55-
run: unzip pr_number.zip
36+
name: pr_number
37+
github-token: ${{ secrets.GITHUB_TOKEN }}
38+
run-id: ${{ github.event.workflow_run.id }}
5639
- name: Get PR context
5740
id: context
5841
env:

tasks/github_tasks.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,12 @@ def get_token_from_app(_, app_id_env='GITHUB_APP_ID', pkey_env='GITHUB_KEY_B64')
155155

156156

157157
def _get_teams(changed_files, owners_file='.github/CODEOWNERS', best_teams_only=True) -> list[str]:
158+
"""Returns a list of teams that are responsible for changed files
159+
160+
:param changed_files: list of changed files
161+
:param owners_file: path to the CODEOWNERS file
162+
:param best_teams_only: if True, returns only the teams with the most changed files
163+
"""
158164
codeowners = read_owners(owners_file)
159165

160166
team_counter = Counter()

0 commit comments

Comments
 (0)