豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

Commit 6da368a

Browse files
committed
feat(github-actions): do not override g3 status if pointing to CL
1 parent 455d625 commit 6da368a

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

github-actions/google-internal-tests/lib/main.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import * as core from '@actions/core';
22
import {context} from '@actions/github';
3-
import {Octokit} from '@octokit/rest';
3+
import {Octokit, RestEndpointMethodTypes} from '@octokit/rest';
44
import minimatch from 'minimatch';
55

6+
const statusContext = 'google-internal-tests';
7+
8+
type GithubStatus =
9+
RestEndpointMethodTypes['repos']['getCombinedStatusForRef']['response']['data']['statuses'][0];
10+
611
async function main() {
712
if (context.repo.owner !== 'angular') {
813
core.info('Skipping Google Internal Tests action for non-Angular repos.');
@@ -26,6 +31,13 @@ async function main() {
2631
const github = new Octokit({auth: githubToken});
2732
const prNum = context.payload.pull_request!.number;
2833
const prHeadSHA = context.payload.pull_request!.head!.sha;
34+
const existingGoogleStatus = await findExistingTestStatus(github, prHeadSHA);
35+
36+
// If there is an existing status already pointing to an internal CL, we do not override
37+
// the status. This can happen when e.g. a presubmit-tested PR is closed and reopened.
38+
if (existingGoogleStatus && existingGoogleStatus.target_url?.startsWith('http://cl/')) {
39+
return;
40+
}
2941

3042
const files = await github.paginate(github.pulls.listFiles, {
3143
...context.repo,
@@ -61,7 +73,7 @@ async function main() {
6173
await github.repos.createCommitStatus({
6274
...context.repo,
6375
...(affectsGoogle ? waitingForG3Status : irrelevantToG3Status),
64-
context: 'google-internal-tests',
76+
context: statusContext,
6577
sha: prHeadSHA,
6678
});
6779
}
@@ -80,6 +92,22 @@ function constructPatterns(rawPatterns: string): minimatch.IMinimatch[] {
8092
return patterns;
8193
}
8294

95+
async function findExistingTestStatus(
96+
github: Octokit,
97+
prHeadSHA: string,
98+
): Promise<GithubStatus | null> {
99+
const existingStatuses = await github.paginate(
100+
github.repos.getCombinedStatusForRef,
101+
{
102+
...context.repo,
103+
ref: prHeadSHA,
104+
},
105+
(r) => r.data.statuses as GithubStatus[],
106+
);
107+
108+
return existingStatuses.find((s) => s.context === statusContext) ?? null;
109+
}
110+
83111
main().catch((e: Error) => {
84112
core.error(e);
85113
core.setFailed(e.message);

github-actions/google-internal-tests/main.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16574,7 +16574,9 @@ var core = __toESM(require_core());
1657416574
var import_github = __toESM(require_github());
1657516575
var import_rest = __toESM(require_dist_node20());
1657616576
var import_minimatch = __toESM(require_minimatch());
16577+
var statusContext = "google-internal-tests";
1657716578
async function main() {
16579+
var _a;
1657816580
if (import_github.context.repo.owner !== "angular") {
1657916581
core.info("Skipping Google Internal Tests action for non-Angular repos.");
1658016582
return;
@@ -16591,6 +16593,10 @@ async function main() {
1659116593
const github = new import_rest.Octokit({ auth: githubToken });
1659216594
const prNum = import_github.context.payload.pull_request.number;
1659316595
const prHeadSHA = import_github.context.payload.pull_request.head.sha;
16596+
const existingGoogleStatus = await findExistingTestStatus(github, prHeadSHA);
16597+
if (existingGoogleStatus && ((_a = existingGoogleStatus.target_url) == null ? void 0 : _a.startsWith("http://cl/"))) {
16598+
return;
16599+
}
1659416600
const files = await github.paginate(github.pulls.listFiles, {
1659516601
...import_github.context.repo,
1659616602
pull_number: prNum
@@ -16616,7 +16622,7 @@ async function main() {
1661616622
await github.repos.createCommitStatus({
1661716623
...import_github.context.repo,
1661816624
...affectsGoogle ? waitingForG3Status : irrelevantToG3Status,
16619-
context: "google-internal-tests",
16625+
context: statusContext,
1662016626
sha: prHeadSHA
1662116627
});
1662216628
}
@@ -16632,6 +16638,13 @@ function constructPatterns(rawPatterns) {
1663216638
}
1663316639
return patterns;
1663416640
}
16641+
async function findExistingTestStatus(github, prHeadSHA) {
16642+
const existingStatuses = await github.paginate(github.repos.getCombinedStatusForRef, {
16643+
...import_github.context.repo,
16644+
ref: prHeadSHA
16645+
}, (r) => r.data.statuses);
16646+
return existingStatuses.find((s) => s.context === statusContext) ?? null;
16647+
}
1663516648
main().catch((e) => {
1663616649
core.error(e);
1663716650
core.setFailed(e.message);

0 commit comments

Comments
 (0)