Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix known issues, add other token types support #23

Merged
merged 11 commits into from
Nov 22, 2021
Next Next commit
feat: add GITLAB_TOKEN_TYPE config
fix: add missing dependencies to package.json
  • Loading branch information
HosseinAgha authored and JounQin committed Nov 22, 2021
commit 1c48cfea6a58ac88d01d2b1fe8293b74187e02d6
7 changes: 7 additions & 0 deletions .changeset/flat-chicken-repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'changesets-gitlab': minor
---

Add missing dependencies to the package.json
JounQin marked this conversation as resolved.
Show resolved Hide resolved
Add support for job tokens and oauth tokens (via GITLAB_TOKEN_TYPE config)
Add eslintcache to gitignore
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
lib
node_modules
.eslintcache
.env
.type-coverage
*.log
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ GLOBAL_AGENT_NO_PROXY # Like above but for no proxied requests
GITLAB_HOST # optional, if you're using custom GitLab host

GITLAB_TOKEN # required, token with accessibility to push
GITLAB_CI_USER_NAME # required, username with accessibility to push, used in pairs of the above token
GITLAB_TOKEN_TYPE # optional, type of the provided token in GITLAB_TOKEN. defaults to personal access token. can be `job` if you provide the Gitlab CI_JOB_TOKEN or `oauth` if you use Gitlab Oauth token
GITLAB_CI_USER_NAME # required, username with accessibility to push, used in pairs of the above token (if it was personal access token)
JounQin marked this conversation as resolved.
Show resolved Hide resolved
GITLAB_CI_USER_EMAIL # optional, default `gitlab[bot]@users.noreply.gitlab.com`
```

Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@
"@actions/exec": "^1.1.0",
"@changesets/assemble-release-plan": "^5.0.2",
"@changesets/config": "^1.6.2",
"@changesets/errors": "^0.1.4",
"@changesets/parse": "^0.3.9",
"@changesets/pre": "^1.0.7",
"@changesets/read": "^0.5.0",
"@changesets/types": "^4.0.0",
"@gitbeaker/node": "^34.6.0",
"@manypkg/get-packages": "^1.1.3",
Expand Down
24 changes: 21 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ declare global {
}
}

type ConstructorArgs<T> = T extends new (...args: infer U) => any ? U : never
type GitlabConfig = ConstructorArgs<typeof Gitlab>[0]

export const createApi = (gitlabToken?: string) => {
bootstrap()

Expand All @@ -22,8 +25,23 @@ export const createApi = (gitlabToken?: string) => {
}
}

return new Gitlab({
const config: GitlabConfig = {
host: process.env.GITLAB_HOST,
token: gitlabToken || process.env.GITLAB_TOKEN,
})
}

const token = gitlabToken || process.env.GITLAB_TOKEN

switch (process.env.GITLAB_TOKEN_TYPE) {
case 'job':
config.jobToken = token
break
case 'oauth':
config.oauthToken = token
break
default:
config.token = token
break
}

return new Gitlab(config)
}
22 changes: 11 additions & 11 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@
dependencies:
"@babel/types" "^7.16.0"

"@babel/helper-hoist-variables@^7.16.0":
"@babel/helper-hoist-variables@^7.14.5", "@babel/helper-hoist-variables@^7.16.0":
version "7.16.0"
resolved "https://registry.yarnpkg.com/@babel/helper-hoist-variables/-/helper-hoist-variables-7.16.0.tgz#4c9023c2f1def7e28ff46fc1dbcd36a39beaa81a"
integrity sha512-1AZlpazjUR0EQZQv3sgRNfM9mEVWPK3M6vlalczA+EECcPz3XPh6VplbErL5UoMpChhSck5wAJHthlj1bYpcmg==
Expand Down Expand Up @@ -554,13 +554,13 @@
"@babel/plugin-proposal-optional-chaining" "^7.16.0"

"@babel/plugin-proposal-async-do-expressions@^7.14.0":
version "7.16.0"
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-async-do-expressions/-/plugin-proposal-async-do-expressions-7.16.0.tgz#c747dc2696cf4018578ee441e2cd60d6585d4e33"
integrity sha512-nrAVI0MW6N+voMBE0MbfscU/vnIGxdhaLU0KgkuGA26hLi+rmrEAdJ/HAXVCx0WOmBXTfhbSP1FlL6lZSIWrTg==
version "7.14.5"
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-async-do-expressions/-/plugin-proposal-async-do-expressions-7.14.5.tgz#0aadb8806809246d64682be1b82a6956015e2077"
integrity sha512-AP38yW7vyOzBY/SS0477k/ddmwpLO3x5rYu5bc+wLpLhfjr+lISt0woizugqQvHdzY4K50rBE+h6JXFQh41TGw==
dependencies:
"@babel/helper-hoist-variables" "^7.16.0"
"@babel/helper-hoist-variables" "^7.14.5"
"@babel/helper-plugin-utils" "^7.14.5"
"@babel/plugin-syntax-async-do-expressions" "^7.16.0"
"@babel/plugin-syntax-async-do-expressions" "^7.14.5"

"@babel/plugin-proposal-async-generator-functions@^7.16.4":
version "7.16.4"
Expand Down Expand Up @@ -767,7 +767,7 @@
"@babel/helper-create-regexp-features-plugin" "^7.16.0"
"@babel/helper-plugin-utils" "^7.14.5"

"@babel/plugin-syntax-async-do-expressions@^7.16.0":
"@babel/plugin-syntax-async-do-expressions@^7.14.5":
version "7.16.0"
resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-async-do-expressions/-/plugin-syntax-async-do-expressions-7.16.0.tgz#5fc7e4bca519979a92fd9596d07baee681e37a01"
integrity sha512-3p9KuwOHUXSx/a52S349DKjnfYWtyims8d8kT7MsTI59HmnTaO4MWT159Nc0e1m8773h/8cG44nVtH2V8dDtJg==
Expand Down Expand Up @@ -1593,7 +1593,7 @@
"@manypkg/get-packages" "^1.0.1"
fs-extra "^7.0.1"

"@changesets/read@^0.5.1":
"@changesets/read@^0.5.0", "@changesets/read@^0.5.1":
version "0.5.1"
resolved "https://registry.yarnpkg.com/@changesets/read/-/read-0.5.1.tgz#89635bf2b84e5fd5d49e1d685adb9c47b5e679a1"
integrity sha512-QJ3rVS+L0Y3yLk3cAOglNh4tuMUfQl8cJjyAnNnJHS9nCXZUiZjYiJc+34XpZT5vUb+4+0FY1wWtzlkAKuLR2g==
Expand Down Expand Up @@ -3057,9 +3057,9 @@ acorn@^7.1.1, acorn@^7.4.0:
integrity sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==

acorn@^8.2.4, acorn@^8.4.1:
version "8.6.0"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.6.0.tgz#e3692ba0eb1a0c83eaa4f37f5fa7368dd7142895"
integrity sha512-U1riIR+lBSNi3IbxtaHOIKdH8sLFv3NYfNv8sg7ZsNhcfl4HF2++BfqqrNAxoCLQW1iiylOj76ecnaUxz+z9yw==
version "8.5.0"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.5.0.tgz#4512ccb99b3698c752591e9bb4472e38ad43cee2"
integrity sha512-yXbYeFy+jUuYd3/CDcg2NkIYE991XYX/bje7LmjJigUciaeO1JR4XxXgCIV1/Zc/dRuFEyw1L0pbA+qynJkW5Q==

agent-base@6:
version "6.0.2"
Expand Down