MCPcopy Create free account
hub / github.com/alibaba/open-code-review / run

Function run

scripts/github-actions/check-pr-commit-policy.js:130–169  ·  view source on GitHub ↗
({ github, context, core })

Source from the content-addressed store, hash-verified

128}
129
130async function run({ github, context, core }) {
131 if (context.eventName !== "pull_request_target" ||
132 !Number.isInteger(context.issue.number) || context.issue.number < 1) {
133 throw new Error("PR Commit Policy requires a pull_request_target event.");
134 }
135 const pullRequest = await readPullRequest(github, {
136 owner: context.repo.owner,
137 repo: context.repo.repo,
138 number: context.issue.number,
139 });
140 if (pullRequest.head !== context.payload.pull_request?.head?.sha) {
141 throw new Error("PR head does not match the triggering event. Re-run PR Commit Policy for the latest PR update.");
142 }
143 if (pullRequest.title !== context.payload.pull_request.title) {
144 throw new Error("PR title does not match the triggering event. Re-run PR Commit Policy for the latest PR update.");
145 }
146 const violations = [];
147 const titleDirectives = findSkipDirectives(pullRequest.title);
148 if (titleDirectives.length) {
149 violations.push(`PR title contains ${titleDirectives.join(", ")}.`);
150 }
151 for (const commit of pullRequest.commits) {
152 const directives = findSkipDirectives(commit.message);
153 if (directives.length) {
154 violations.push(`Commit ${commit.oid} contains ${directives.join(", ")}.`);
155 }
156 }
157
158 if (violations.length) {
159 for (const violation of violations.slice(0, 20)) core.error(violation);
160 core.setFailed(
161 `Found CI skip directives in ${violations.length} PR title/commit message(s). ` +
162 "Remove them from the title and rewrite affected commit messages; " +
163 "adding a clean commit does not remove earlier violations. " +
164 "See CONTRIBUTING.md#commit-messages. At most 20 violations are shown."
165 );
166 } else {
167 core.info(`PR title and all ${pullRequest.commits.length} commit messages contain no CI skip directives.`);
168 }
169}
170
171module.exports = { findSkipDirectives, readPullRequest, run };

Callers 12

TestDelegatePagerPTYFunction · 0.50
initRepoFunction · 0.50
initTestRepoFunction · 0.50
initPreviewRepoFunction · 0.50
initTraceParentRepoFunction · 0.50
setupTestRepoFunction · 0.50
executeMethod · 0.50
setupFileFindRepoFunction · 0.50

Calls 2

readPullRequestFunction · 0.85
findSkipDirectivesFunction · 0.85

Tested by 10

TestDelegatePagerPTYFunction · 0.40
initRepoFunction · 0.40
initTestRepoFunction · 0.40
initPreviewRepoFunction · 0.40
initTraceParentRepoFunction · 0.40
setupTestRepoFunction · 0.40
setupFileFindRepoFunction · 0.40