Skip to content

Commit e021246

Browse files
albthalipepakriz
andauthored
Adding Http proxy (#134)
* initial changes * fixed http proxy in index and config * adding helm * Fix some type errors Co-authored-by: Josef Kříž <[email protected]>
1 parent 5a32699 commit e021246

File tree

9 files changed

+96
-24
lines changed

9 files changed

+96
-24
lines changed

README.md

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -82,21 +82,22 @@ GITLAB_AUTH_TOKEN="<token>" yarn run start
8282

8383
#### Configuration options
8484

85-
| Env variable | Default value | |
86-
|-------------------|--------------------|-------------------|
87-
| `GITLAB_URL` | `https://gitlab.com` | GitLab instance URL |
88-
| `GITLAB_AUTH_TOKEN` | | `required` Your GitLab token |
89-
| `CI_CHECK_INTERVAL` | `10` | Time between CI checks (in seconds) |
90-
| `MR_CHECK_INTERVAL` | `20` | Time between merge-requests checks (in seconds) |
91-
| `REMOVE_BRANCH_AFTER_MERGE` | `true` | It'll remove branch after merge |
92-
| `SQUASH_MERGE_REQUEST` | `true` | It'll squash commits on merge |
93-
| `AUTORUN_MANUAL_BLOCKING_JOBS` | `true` | It'll autorun manual blocking jobs before merge |
94-
| `SKIP_SQUASHING_LABEL` | `bot:skip-squash` | It'll skip squash when MR contains this label |
95-
| `HI_PRIORITY_LABEL` | `bot:high-priority` | It'll put MR with this label to the beginning of the queue |
96-
| `SENTRY_DSN` | `` | It'll enable Sentry monitoring |
97-
| `HTTP_SERVER_ENABLE` | `false` | It'll enable experimental API and dashboard support |
98-
| `HTTP_SERVER_PORT` | `4000` | It'll use different http server port |
99-
| `WEB_HOOK_TOKEN` | `` | It'll enable experimental web hook support |
85+
| Env variable | Default value | |
86+
|--------------------------------|----------------------|------------------------------------------------------------|
87+
| `GITLAB_URL` | `https://gitlab.com` | GitLab instance URL |
88+
| `GITLAB_AUTH_TOKEN` | | `required` Your GitLab token |
89+
| `HTTP_PROXY` | `` | Use HTTP proxy for API communication |
90+
| `CI_CHECK_INTERVAL` | `10` | Time between CI checks (in seconds) |
91+
| `MR_CHECK_INTERVAL` | `20` | Time between merge-requests checks (in seconds) |
92+
| `REMOVE_BRANCH_AFTER_MERGE` | `true` | It'll remove branch after merge |
93+
| `SQUASH_MERGE_REQUEST` | `true` | It'll squash commits on merge |
94+
| `AUTORUN_MANUAL_BLOCKING_JOBS` | `true` | It'll autorun manual blocking jobs before merge |
95+
| `SKIP_SQUASHING_LABEL` | `bot:skip-squash` | It'll skip squash when MR contains this label |
96+
| `HI_PRIORITY_LABEL` | `bot:high-priority` | It'll put MR with this label to the beginning of the queue |
97+
| `SENTRY_DSN` | `` | It'll enable Sentry monitoring |
98+
| `HTTP_SERVER_ENABLE` | `false` | It'll enable experimental API and dashboard support |
99+
| `HTTP_SERVER_PORT` | `4000` | It'll use different http server port |
100+
| `WEB_HOOK_TOKEN` | `` | It'll enable experimental web hook support |
100101

101102
## Development
102103

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ spec:
6464
value: "{{ .Values.settings.httpServerPort }}"
6565
- name: WEB_HOOK_TOKEN
6666
value: "{{ .Values.settings.webHookToken }}"
67+
{{- if .Values.settings.httpProxy }}
68+
- name: HTTP_PROXY
69+
valueFrom:
70+
secretKeyRef:
71+
key: httpProxy
72+
name: {{ .Values.settings.httpProxySecretName }}
73+
{{- end }}
6774
{{- range $key, $value := .Values.env }}
6875
- name: "{{ $key }}"
6976
value: "{{ $value }}"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{{- if .Values.settings.httpProxy}}
2+
Kind: Secret
3+
metadata:
4+
name: {{ .Values.settings.httpProxySecretName }}
5+
namespace: {{ include "gitlab-merger-bot.namespace" . }}
6+
type: Opaque
7+
data:
8+
httpProxy: {{ .Values.settings.httpProxy | b64enc }}
9+
10+
{{- end }}

charts/gitlab-merger-bot/values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,5 @@ settings:
6868
httpServerEnable: false
6969
httpServerPort: 4000
7070
webHookToken: ""
71+
httpProxySecretName: http-proxy
72+
httpProxy: ""

server/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
"express": "^4.17.1",
2424
"fast-deep-equal": "^3.1.3",
2525
"graphql": "^14.7.0",
26-
"node-fetch": "^2.6.1",
26+
"https-proxy-agent": "^5.0.1",
27+
"node-fetch": "^2.6.7",
2728
"serve-static": "^1.14.1",
2829
"uuid": "^8.3.0"
2930
},
@@ -37,7 +38,7 @@
3738
"@types/express": "^4.17.7",
3839
"@types/jest": "^26.0.10",
3940
"@types/node": "^14.6.0",
40-
"@types/node-fetch": "^2.5.7",
41+
"@types/node-fetch": "^2.6.1",
4142
"@types/uuid": "^8.3.0",
4243
"@types/webpack": "^4.41.21",
4344
"@types/webpack-node-externals": "^2.5.0",

server/src/Config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export const defaultConfig = {
1414
HTTP_SERVER_PORT: 4000,
1515
WEB_HOOK_TOKEN: '',
1616
DRY_RUN: false,
17+
HTTP_PROXY: '',
1718
};
1819

1920
export const getConfig = (): Config => ({
@@ -55,6 +56,7 @@ export const getConfig = (): Config => ({
5556
.asPortNumber(),
5657
WEB_HOOK_TOKEN: env.get('WEB_HOOK_TOKEN').default(defaultConfig.WEB_HOOK_TOKEN).asString(),
5758
DRY_RUN: env.get('DRY_RUN').default(`${defaultConfig.DRY_RUN}`).asBoolStrict(),
59+
HTTP_PROXY: env.get('HTTP_PROXY').default('').asString(),
5860
});
5961

6062
export type Config = typeof defaultConfig;

server/src/GitlabApi.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import fetch, { FetchError, RequestInit, Response } from 'node-fetch';
22
import queryString, { ParsedUrlQueryInput } from 'querystring';
33
import { sleep } from './Utils';
4+
import { HttpsProxyAgent } from 'https-proxy-agent';
45

56
export interface User {
67
id: number;
@@ -135,10 +136,12 @@ export enum RequestMethod {
135136
export class GitlabApi {
136137
private readonly gitlabUrl: string;
137138
private readonly authToken: string;
139+
private readonly httpProxy: HttpsProxyAgent | undefined;
138140

139-
constructor(gitlabUrl: string, authToken: string) {
141+
constructor(gitlabUrl: string, authToken: string, httpProxy: string | undefined) {
140142
this.gitlabUrl = gitlabUrl;
141143
this.authToken = authToken;
144+
this.httpProxy = httpProxy ? new HttpsProxyAgent(httpProxy) : undefined;
142145
}
143146

144147
public async getMe(): Promise<User> {
@@ -331,6 +334,7 @@ export class GitlabApi {
331334
'Private-Token': this.authToken,
332335
'Content-Type': 'application/json',
333336
},
337+
agent: this.httpProxy,
334338
};
335339

336340
if (body !== undefined) {

server/src/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ if (SENTRY_DSN !== '') {
1313
}
1414

1515
const config = getConfig();
16-
const gitlabApi = new GitlabApi(config.GITLAB_URL, config.GITLAB_AUTH_TOKEN);
16+
const gitlabApi = new GitlabApi(
17+
config.GITLAB_URL,
18+
config.GITLAB_AUTH_TOKEN,
19+
config.HTTP_PROXY !== '' ? config.HTTP_PROXY : undefined,
20+
);
1721
const pubSub = new PubSub();
1822
const worker = new Worker(pubSub, config);
1923

yarn.lock

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2667,14 +2667,22 @@
26672667
"@types/node" "*"
26682668
form-data "^3.0.0"
26692669

2670-
"@types/[email protected]", "@types/node-fetch@^2.5.7":
2670+
26712671
version "2.5.7"
26722672
resolved "https://registry.yarnpkg.com/@types/node-fetch/-/node-fetch-2.5.7.tgz#20a2afffa882ab04d44ca786449a276f9f6bbf3c"
26732673
integrity sha512-o2WVNf5UhWRkxlf6eq+jMZDu7kjgpgJfl4xVNlvryc95O/6F2ld8ztKX+qu+Rjyet93WAWm5LjeX9H5FGkODvw==
26742674
dependencies:
26752675
"@types/node" "*"
26762676
form-data "^3.0.0"
26772677

2678+
"@types/node-fetch@^2.6.1":
2679+
version "2.6.1"
2680+
resolved "https://registry.yarnpkg.com/@types/node-fetch/-/node-fetch-2.6.1.tgz#8f127c50481db65886800ef496f20bbf15518975"
2681+
integrity sha512-oMqjURCaxoSIsHSr1E47QHzbmzNR5rK8McHuNb11BOM9cHcIK3Avy0s/b2JlXHoQGTYS3NsvWzV1M0iK7l0wbA==
2682+
dependencies:
2683+
"@types/node" "*"
2684+
form-data "^3.0.0"
2685+
26782686
"@types/node@*":
26792687
version "13.11.1"
26802688
resolved "https://registry.yarnpkg.com/@types/node/-/node-13.11.1.tgz#49a2a83df9d26daacead30d0ccc8762b128d53c7"
@@ -3077,9 +3085,9 @@ [email protected]:
30773085
regex-parser "2.2.10"
30783086

30793087
agent-base@6:
3080-
version "6.0.1"
3081-
resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-6.0.1.tgz#808007e4e5867decb0ab6ab2f928fbdb5a596db4"
3082-
integrity sha512-01q25QQDwLSsyfhrKbn8yuur+JNw0H+0Y4JiGIKd3z9aYk/w/2kxD/Upc+t2ZBBSUNff50VjPsSW2YxM8QYKVg==
3088+
version "6.0.2"
3089+
resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-6.0.2.tgz#49fff58577cfee3f37176feab4c22e00f86d7f77"
3090+
integrity sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==
30833091
dependencies:
30843092
debug "4"
30853093

@@ -6525,6 +6533,14 @@ [email protected], https-proxy-agent@^5.0.0:
65256533
agent-base "6"
65266534
debug "4"
65276535

6536+
https-proxy-agent@^5.0.1:
6537+
version "5.0.1"
6538+
resolved "https://registry.yarnpkg.com/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz#c59ef224a04fe8b754f3db0063a25ea30d0005d6"
6539+
integrity sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA==
6540+
dependencies:
6541+
agent-base "6"
6542+
debug "4"
6543+
65286544
human-signals@^1.1.1:
65296545
version "1.1.1"
65306546
resolved "https://registry.yarnpkg.com/human-signals/-/human-signals-1.1.1.tgz#c5b1cd14f50aeae09ab6c59fe63ba3395fe4dfa3"
@@ -8606,11 +8622,18 @@ node-fetch@^1.0.1, node-fetch@^1.7.3:
86068622
encoding "^0.1.11"
86078623
is-stream "^1.0.1"
86088624

8609-
node-fetch@^2.1.2, node-fetch@^2.2.0, node-fetch@^2.6.1:
8625+
node-fetch@^2.1.2, node-fetch@^2.2.0:
86108626
version "2.6.1"
86118627
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.1.tgz#045bd323631f76ed2e2b55573394416b639a0052"
86128628
integrity sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==
86138629

8630+
node-fetch@^2.6.7:
8631+
version "2.6.7"
8632+
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad"
8633+
integrity sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==
8634+
dependencies:
8635+
whatwg-url "^5.0.0"
8636+
86148637
node-html-parser@^1.2.19:
86158638
version "1.2.20"
86168639
resolved "https://registry.yarnpkg.com/node-html-parser/-/node-html-parser-1.2.20.tgz#37e9ebc627dbe3ff446eea4ac93e3d254b7c6ee4"
@@ -11185,6 +11208,11 @@ tr46@^2.0.2:
1118511208
dependencies:
1118611209
punycode "^2.1.1"
1118711210

11211+
tr46@~0.0.3:
11212+
version "0.0.3"
11213+
resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a"
11214+
integrity sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o=
11215+
1118811216
1118911217
version "0.6.6"
1119011218
resolved "https://registry.yarnpkg.com/traverse/-/traverse-0.6.6.tgz#cbdf560fd7b9af632502fed40f918c157ea97137"
@@ -11702,6 +11730,11 @@ [email protected]:
1170211730
resolved "https://registry.yarnpkg.com/web-vitals/-/web-vitals-0.2.1.tgz#60782fa690243fe35613759a0c26431f57ba7b2d"
1170311731
integrity sha512-2pdRlp6gJpOCg0oMMqwFF0axjk5D9WInc09RSYtqFgPXQ15+YKNQ7YnBBEqAL5jvmfH9WvoXDMb8DHwux7pIew==
1170411732

11733+
webidl-conversions@^3.0.0:
11734+
version "3.0.1"
11735+
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871"
11736+
integrity sha1-JFNCdeKnvGvnvIZhHMFq4KVlSHE=
11737+
1170511738
webidl-conversions@^4.0.2:
1170611739
version "4.0.2"
1170711740
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-4.0.2.tgz#a855980b1f0b6b359ba1d5d9fb39ae941faa63ad"
@@ -11818,6 +11851,14 @@ whatwg-mimetype@^2.3.0:
1181811851
resolved "https://registry.yarnpkg.com/whatwg-mimetype/-/whatwg-mimetype-2.3.0.tgz#3d4b1e0312d2079879f826aff18dbeeca5960fbf"
1181911852
integrity sha512-M4yMwr6mAnQz76TbJm914+gPpB/nCwvZbJU28cUD6dR004SAxDLOOSUaB1JDRqLtaOV/vi0IC5lEAGFgrjGv/g==
1182011853

11854+
whatwg-url@^5.0.0:
11855+
version "5.0.0"
11856+
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-5.0.0.tgz#966454e8765462e37644d3626f6742ce8b70965d"
11857+
integrity sha1-lmRU6HZUYuN2RNNib2dCzotwll0=
11858+
dependencies:
11859+
tr46 "~0.0.3"
11860+
webidl-conversions "^3.0.0"
11861+
1182111862
whatwg-url@^7.0.0:
1182211863
version "7.1.0"
1182311864
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-7.1.0.tgz#c2c492f1eca612988efd3d2266be1b9fc6170d06"

0 commit comments

Comments
 (0)