Skip to content

Commit 1c53606

Browse files
Merge branch 'main' into refactor/load-users
2 parents 60cb11a + a31cf99 commit 1c53606

File tree

1 file changed

+33
-34
lines changed

1 file changed

+33
-34
lines changed

.github/workflows/pr.yml

+33-34
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ jobs:
1919
pull-requests: read
2020
outputs:
2121
has-files-requiring-all-checks: ${{ steps.filter.outputs.has-files-requiring-all-checks }}
22+
commit-sha: ${{ steps.get_sha.outputs.commit-sha }}
2223
steps:
2324
- uses: actions/checkout@v4
2425
- uses: ./.github/actions/dangerous-git-checkout
@@ -28,59 +29,57 @@ jobs:
2829
filters: |
2930
has-files-requiring-all-checks:
3031
- "!(**.md|.github/CODEOWNERS)"
32+
- name: Get Latest Commit SHA
33+
id: get_sha
34+
run: |
35+
echo "commit-sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
3136
3237
check-label:
38+
needs: [changes]
3339
runs-on: buildjet-2vcpu-ubuntu-2204
3440
name: Check for E2E label
3541
outputs:
36-
run-e2e: ${{ steps.check-if-pr-has-label.outputs.run-e2e == 'true' && (github.event_name != 'labeled' || (github.event_name == 'labeled' && github.event.label.name == 'ready-for-e2e')) }}
37-
run-jobs: ${{ github.event_name != 'labeled' }}
42+
run-e2e: ${{ steps.check-if-pr-has-label.outputs.run-e2e == 'true' && (github.event.action != 'labeled' || (github.event.action == 'labeled' && github.event.label.name == 'ready-for-e2e')) }}
43+
run-jobs: ${{ github.event.action != 'labeled' }}
3844
steps:
39-
- name: Get PR from branch name
45+
- name: Check if PR exists with ready-for-e2e label for this SHA
4046
id: check-if-pr-has-label
4147
uses: actions/github-script@v7
4248
with:
4349
script: |
44-
let pr;
45-
console.log('github.event_name', '${{ github.event_name }}');
46-
const parsedEvent = ${{ github.event }};
47-
if (parsedEvent && parsedEvent.pull_request) {
48-
const response = await github.rest.pulls.get({
49-
owner: github.context.repo.owner,
50-
repo: github.context.repo.repo,
51-
pull_number: parsedEvent.pull_request.number
52-
});
53-
54-
pr = response.data;
55-
} else {
56-
const ref = '${{ github.ref }}';
57-
const branch = ref.replace('refs/heads/', '');
58-
console.log('ref', ref);
59-
console.log('branch', branch);
60-
const response = await github.rest.pulls.list({
50+
console.log('github.event.action', '${{ github.event.action }}');
51+
try {
52+
const sha = '${{ needs.changes.outputs.commit-sha }}';
53+
console.log('sha', sha);
54+
const { data: prs } = await github.rest.repos.listPullRequestsAssociatedWithCommit({
6155
owner: context.repo.owner,
6256
repo: context.repo.repo,
63-
state: 'open',
64-
head: `${context.repo.owner}:${branch}`
57+
commit_sha: sha
6558
});
6659
67-
if (response.data.length > 0) {
68-
pr = response.data[0];
60+
if (prs.length === 0) {
61+
core.setOutput('run-e2e', false);
62+
console.log(`No pull requests found for commit SHA ${sha}`);
63+
return;
6964
}
70-
}
7165
72-
if (!pr) {
66+
const pr = prs[0];
67+
console.log(`PR number: ${pr.number}`);
68+
console.log(`PR title: ${pr.title}`);
69+
console.log(`PR state: ${pr.state}`);
70+
console.log(`PR URL: ${pr.html_url}`);
71+
72+
const labels = pr.labels.map(label => label.name);
73+
const labelFound = labels.includes('ready-for-e2e');
74+
console.log('PR #', pr.number);
75+
console.log('Found the label?', labelFound);
76+
core.setOutput('run-e2e', labelFound);
77+
}
78+
catch (e) {
7379
core.setOutput('run-e2e', false);
74-
console.log('No PR found');
75-
return;
80+
console.log(e);
7681
}
7782
78-
const labels = pr.labels.map(label => label.name);
79-
const labelFound = labels.includes('ready-for-e2e');
80-
console.log('PR #', pr.number);
81-
console.log('Found the label?', labelFound);
82-
core.setOutput('run-e2e', labelFound);
83-
8483
type-check:
8584
name: Type check
8685
needs: [changes, check-label]

0 commit comments

Comments
 (0)