-
Notifications
You must be signed in to change notification settings - Fork 153
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
第九讲课后作业(截止时间5月28日) #139
Comments
liao old NB!!! |
14 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
目标
写一个 github action,监听 issue comment 的创建事件,假如 comment 归属某些用户,那么就给这个 issue comment 添加一个互动 reaction,比如 eyes。
目的是帮助同学练习和深入理解 github action 的使用。
实现
oss101/.github/workflows/add-reaction.yaml
Lines 1 to 22 in b802415
示例仓库:TieWay59/issue-action-test
原理是借助环境变量筛选条件然后 curl github api。
Reaction API1
其中:
application/vnd.github+json
是 Github API 使用的自定义媒体类型2。它允许指定 API 版本和返回数据的格式。vnd 是 vendor 的缩写,表示这是一个供应商特定的媒体类型。<YOUR-TOKEN>
如果想要在 action 脚本中使用用户的 token,需要创建一个属于该用户的 Personal Access Token (PAT),然后将它存储在仓库或组织的 secrets 中,然后在 action 中使用${{ secrets.PAT_NAME }}
来引用它。上面的secrets.TIEWAY59_PAT
就是我个人的 token。Personal Access Token3
相关的设置藏在
Settings > Developer settings > Personal access tokens
小节中。创建 Fine-grained PAT 需要定制需要启用的读写权限,这一步需要稍微注意一些。创建 PAT 以后, 打开仓库设置
Settings > secrets > Actions
点击new repository secret
添加 PAT。这里设置的变量名就是之后脚本中secrets.
可以访问的变量名。实践任务
(基础版)阅读以上材料,个人向课程仓库提交 PR,把自己的用户 login 加入到监听列表。
oss101/.github/workflows/add-reaction.yaml
Lines 10 to 13 in b802415
ci: add `<YOUR-LOGIN>` to reaction list
,比如ci: add `tieway59` to reaction list
。 PR 标题与此 commit 标题一致。.github/workflows/add-reaction.yml
文件,并且只会添加一行修改。(进阶版-选做)在自己的某个仓库加入类似的功能,提交简单的报告,以博客链接的形式放到本 issue 下方。
截止时间:5 月 28 日 23:59,请在截止日期前提交 PR,并确保 PR 能够被合并。逾期提交或提交失败的作业将不予评分。
Footnotes
Create reaction for an issue comment ↩
What is the application/vnd.github+json media type? - Stack Overflow ↩
Creating a personal access token - GitHub Docs ↩
The text was updated successfully, but these errors were encountered: