-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepository.ts
53 lines (47 loc) · 1.98 KB
/
repository.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
* SPDX-FileCopyrightText: 2023 Kevin de Jong <monkaii@hotmail.com>
* SPDX-License-Identifier: MIT
*/
import * as core from "@actions/core";
import type { components as octokitComponents } from "@octokit/openapi-types";
type Repository = octokitComponents["schemas"]["repository"];
/**
* Checks the repository merge configuration;
* - Whether merge commits are enabled and whether the default subject is based on the Pull Request title
* - Whether squash commits are enabled and whether the default subject is based on the Pull Request title
* - Whether rebase commits are enabled
*/
export function checkConfiguration(repository: Repository): void {
if (
repository.allow_merge_commit === undefined ||
repository.allow_squash_merge === undefined ||
repository.allow_rebase_merge === undefined
) {
throw new Error(
"❌ CommitMe is not configured correctly. Please provide either:\n - The `contents: write` permission, or\n - Use the `include-commits` input parameter."
);
}
if (repository.allow_merge_commit) {
core.info(
repository.merge_commit_title === "PR_TITLE"
? "✅ Default merge commit subject will use the Pull Request title."
: "⚠️ Default merge commit subject is not based on your Pull Request title."
);
} else {
core.info("ℹ️ Merge commit strategy is disabled.");
}
if (repository.allow_squash_merge === true) {
core.info(
repository.squash_merge_commit_title === "PR_TITLE"
? "✅ Default squash commit subject will use the Pull Request title."
: "⚠️ Default squash commit subject is based on either your Commit message or Pull Request title."
);
} else {
core.info("ℹ️ Squash commit strategy is disabled.");
}
core.info(
repository.allow_rebase_merge === true
? "ℹ️ Rebase merges are enabled, validating both Pull Request title and all associated commits."
: "ℹ️ Rebase merges are disabled, only validating the Pull Request title."
);
}