功能
dangerjscan look for these kind of issues and alert the author of PR by a comment.
也就是说 dangerjs 是通过评论的方式来提示 pull request 或者 merge request 的提交者。而不是一种强制的校验。
获取 api
通过dangerjs 的 gitlab 文档可以获取,但是发现 author 这个字段的类型是 gitlabUser,但是 gitlabUser 下面有哪些字段就不知道了。可以通过它的 playground 的提示来看。
创建私人 access token
参考 docs.gitlab.com/ee/user/pro…
You can create as many personal access tokens as you like.
- In the top-right corner, select your avatar.
- Select Edit profile.
- On the left sidebar, select Access Tokens.
- Enter a name and optional expiry date for the token.
- Select the desired scopes.
- Select Create personal access token.
Save the personal access token somewhere safe. After you leave the page, you no longer have access to the token.
特别要注意的就是最后一句话,一定记得拷贝创建好的 access token,否则离开这个页面就找不到了。
在 .gitlab-ci.yml 中添加 access token 变量
variables:
DANGER_GITLAB_API_TOKEN: "BxxxxxxxxxxxxxwS8"
确认 gitlab 的版本号
通过在浏览器中输入 your-gitlab-url/help 可以获取到
gitlab ci 报错
执行 gitlab-ci 的时候报如下错误
Fetching changes with git depth set to 50...
Reinitialized existing Git repository in /home/gitlab-runner/builds/78xSxGiD/0/fe/test_demo/.git/
fatal: git fetch-pack: expected shallow list
fatal: The remote end hung up unexpectedly
Cleaning up file based variables00:00
ERROR: Job failed: exit status 1
查了下是因为服务器上 git 的版本太低导致的。所以需要升级一下服务器上的 git,具体步骤见下面的内容。
升级 git
参考 megamorf.gitlab.io/2020/03/19/…
# First, uninstall the original git package
# Note that this will also remove the gitlab-runner package because it has defined git as dependency
sudo yum remove git
# Install the ius repository (new URL!)
sudo yum install -y https://repo.ius.io/ius-release-el7.rpm
# Install specific IUS version of the git package
# Note the hardcoded version in the package name. For details check:
# - https://github.com/iusrepo/wishlist/issues/241#issue-454462839
# - https://github.com/iusrepo/git222/issues/6
# To always install the latest IUS version of git run the following instead:
# sudo yum install --exclude git git sudo yum install git222
# Finally, reinstall and enable the gitlab-runner:
sudo yum install gitlab-runner
sudo systemctl enable gitlab-runner
sudo systemctl start gitlab-runner
参考文章
www.twomeetings.com/2020-07-14-… blog.revathskumar.com/2019/05/set…