Skip to content

Commit 17f43e2

Browse files
authored
Option for whitelisting of watched projects (#194)
1 parent acd539d commit 17f43e2

File tree

5 files changed

+41
-18
lines changed

5 files changed

+41
-18
lines changed

README.md

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -85,24 +85,25 @@ GITLAB_AUTH_TOKEN="<token>" yarn run start
8585

8686
#### Configuration options
8787

88-
| Env variable | Default value | |
89-
|--------------------------------|----------------------|------------------------------------------------------------|
90-
| `GITLAB_URL` | `https://gitlab.com` | GitLab instance URL |
91-
| `GITLAB_AUTH_TOKEN` | | `required` Your GitLab token |
92-
| `HTTP_PROXY` | `` | Use HTTP proxy for API communication |
93-
| `CI_CHECK_INTERVAL` | `10` | Time between CI checks (in seconds) |
94-
| `MR_CHECK_INTERVAL` | `20` | Time between merge-requests checks (in seconds) |
95-
| `REMOVE_BRANCH_AFTER_MERGE` | `true` | It'll remove branch after merge |
96-
| `SQUASH_MERGE_REQUEST` | `true` | It'll squash commits on merge |
97-
| `PREFER_GITLAB_TEMPLATE` | `false` | Use Gitlab template instead of custom message |
98-
| `AUTORUN_MANUAL_BLOCKING_JOBS` | `true` | It'll autorun manual blocking jobs before merge |
99-
| `SKIP_SQUASHING_LABEL` | `bot:skip-squash` | It'll skip squash when MR contains this label |
100-
| `HIGH_PRIORITY_LABEL` | `bot:high-priority` | It'll put MR with this label to the beginning of the queue |
101-
| `SENTRY_DSN` | `` | It'll enable Sentry monitoring |
102-
| `HTTP_SERVER_ENABLE` | `false` | It'll enable experimental API and dashboard support |
103-
| `HTTP_SERVER_PORT` | `4000` | It'll use different http server port |
104-
| `WEB_HOOK_TOKEN` | `` | It'll enable experimental web hook support |
105-
| `ENABLE_PERMISSION_VALIDATION` | `false` | It'll enable experimental permission validation |
88+
| Env variable | Default value | |
89+
|--------------------------------|----------------------|----------------------------------------------------------------------------|
90+
| `GITLAB_URL` | `https://gitlab.com` | GitLab instance URL |
91+
| `GITLAB_AUTH_TOKEN` | | `required` Your GitLab token |
92+
| `ALLOWED_PROJECT_IDS` | `` | It'll restrict operation only on selected projects. (comma separated list) |
93+
| `HTTP_PROXY` | `` | Use HTTP proxy for API communication |
94+
| `CI_CHECK_INTERVAL` | `10` | Time between CI checks (in seconds) |
95+
| `MR_CHECK_INTERVAL` | `20` | Time between merge-requests checks (in seconds) |
96+
| `REMOVE_BRANCH_AFTER_MERGE` | `true` | It'll remove branch after merge |
97+
| `SQUASH_MERGE_REQUEST` | `true` | It'll squash commits on merge |
98+
| `PREFER_GITLAB_TEMPLATE` | `false` | Use Gitlab template instead of custom message |
99+
| `AUTORUN_MANUAL_BLOCKING_JOBS` | `true` | It'll autorun manual blocking jobs before merge |
100+
| `SKIP_SQUASHING_LABEL` | `bot:skip-squash` | It'll skip squash when MR contains this label |
101+
| `HIGH_PRIORITY_LABEL` | `bot:high-priority` | It'll put MR with this label to the beginning of the queue |
102+
| `SENTRY_DSN` | `` | It'll enable Sentry monitoring |
103+
| `HTTP_SERVER_ENABLE` | `false` | It'll enable experimental API and dashboard support |
104+
| `HTTP_SERVER_PORT` | `4000` | It'll use different http server port |
105+
| `WEB_HOOK_TOKEN` | `` | It'll enable experimental web hook support |
106+
| `ENABLE_PERMISSION_VALIDATION` | `false` | It'll enable experimental permission validation |
106107

107108
## Development
108109

charts/gitlab-merger-bot/templates/deployment.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ spec:
3939
value: "{{ .Values.settings.authToken }}"
4040
- name: GITLAB_URL
4141
value: "{{ .Values.settings.gitlabUrl }}"
42+
- name: ALLOWED_PROJECT_IDS
43+
value: "{{ .Values.settings.allowedProjectIds }}"
4244
- name: CI_CHECK_INTERVAL
4345
value: "{{ .Values.settings.ciCheckInterval }}"
4446
- name: MR_CHECK_INTERVAL

charts/gitlab-merger-bot/values.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ settings:
7878
gitlabUrl: "https://gitlab.com"
7979
authToken: ""
8080
sentryDsn: ""
81+
allowedProjectIds: ""
8182
ciCheckInterval: 10
8283
mrCheckInterval: 20
8384
removeBranchAfterMerge: true

server/src/Config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export const defaultConfig = {
1717
DRY_RUN: false,
1818
HTTP_PROXY: '',
1919
ENABLE_PERMISSION_VALIDATION: false,
20+
ALLOWED_PROJECT_IDS: [] as string[],
2021
};
2122

2223
export const getConfig = (): Config => ({
@@ -71,6 +72,10 @@ export const getConfig = (): Config => ({
7172
.get('ENABLE_PERMISSION_VALIDATION')
7273
.default(`${defaultConfig.ENABLE_PERMISSION_VALIDATION}`)
7374
.asBoolStrict(),
75+
ALLOWED_PROJECT_IDS: env
76+
.get('ALLOWED_PROJECT_IDS')
77+
.default(`${defaultConfig.ALLOWED_PROJECT_IDS}`)
78+
.asArray(),
7479
});
7580

7681
export type Config = typeof defaultConfig;

server/src/MergeRequestReceiver.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,20 @@ export const prepareMergeRequestForMerge = async (
9393
return;
9494
}
9595

96+
if (
97+
config.ALLOWED_PROJECT_IDS.length > 0 &&
98+
!config.ALLOWED_PROJECT_IDS.includes(mergeRequest.target_project_id.toString())
99+
) {
100+
await Promise.all([
101+
assignToAuthorAndResetLabels(gitlabApi, mergeRequest, user),
102+
sendNote(
103+
gitlabApi,
104+
mergeRequest,
105+
`I can't merge it because I'm not allowed to operate on this project.`,
106+
),
107+
]);
108+
}
109+
96110
// Validate permissions
97111
if (author !== null) {
98112
const protectedBranch = await gitlabApi.getProtectedBranch(

0 commit comments

Comments
 (0)