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

第九讲课后作业(截止时间5月28日) #139

Closed
TieWay59 opened this issue May 8, 2023 · 14 comments
Closed

第九讲课后作业(截止时间5月28日) #139

TieWay59 opened this issue May 8, 2023 · 14 comments
Assignees

Comments

@TieWay59
Copy link
Member

TieWay59 commented May 8, 2023

实践任务部分见文章末尾

目标

写一个 github action,监听 issue comment 的创建事件,假如 comment 归属某些用户,那么就给这个 issue comment 添加一个互动 reaction,比如 eyes。

目的是帮助同学练习和深入理解 github action 的使用。

实现

name: Add reaction
on:
issue_comment:
types: [created]
jobs:
reaction:
runs-on: ubuntu-latest
if: |
contains(fromJson('
[
"tc2000731",
"will-ww",
]'), github.event.sender.login)
steps:
- name: Add reaction
run: |
curl -X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: token ${{ secrets.TIEWAY59_PAT }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{ github.repository }}/issues/comments/${{ github.event.comment.id }}/reactions \
-d '{"content": "eyes"}'

name: Add reaction
on:
  issue_comment:
    types: [created]
jobs:
  reaction:
    runs-on: ubuntu-latest
    if: |
      contains(fromJson('
        [
          "tc2000731",
          "will-ww",
        ]'), github.event.sender.login)
    steps:
      - name: Add reaction
        run: |
          curl -X POST \
            -H "Accept: application/vnd.github+json" \
            -H "Authorization: token ${{ secrets.TIEWAY59_PAT }}" \
            -H "X-GitHub-Api-Version: 2022-11-28" \
            https://api.github.com/repos/${{ github.repository }}/issues/comments/${{ github.event.comment.id }}/reactions \
            -d '{"content": "eyes"}'

示例仓库:TieWay59/issue-action-test

原理是借助环境变量筛选条件然后 curl github api。

Reaction API1

curl -L \
  -X POST \
  -H "Accept: application/vnd.github+json" \
  -H "Authorization: Bearer <YOUR-TOKEN>" \
  -H "X-GitHub-Api-Version: 2022-11-28" \
  https://api.github.com/repos/OWNER/REPO/issues/comments/COMMENT_ID/reactions \
  -d '{"content":"heart"}'

其中:

  • 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. 可以访问的变量名。

实践任务

  1. (基础版)阅读以上材料,个人向课程仓库提交 PR,把自己的用户 login 加入到监听列表。

    1. [
      "tc2000731",
      "will-ww",
      ]'), github.event.sender.login)
    2. 本作业的 PR 应该只包含一个 commit 名为 ci: add `<YOUR-LOGIN>` to reaction list,比如 ci: add `tieway59` to reaction list。 PR 标题与此 commit 标题一致。
    3. PR 正文部分可以留空。
    4. 作业 PR 应该只修改 .github/workflows/add-reaction.yml 文件,并且只会添加一行修改。
    5. 由于可能出现冲突的情况,助教建议采用强制提交修改历史的操作保持 PR 的原子性。
  2. (进阶版-选做)在自己的某个仓库加入类似的功能,提交简单的报告,以博客链接的形式放到本 issue 下方。

    1. 不必和课程提供的练习一致,比如 reaction 内容还有 heart 等其他选择。
    2. 反馈格式:
    51215903062
    仓库链接: https://github.com/TieWay59/issue-action-test
    报告链接: https://github.com/TieWay59/issue-action-test
  3. 截止时间:5 月 28 日 23:59,请在截止日期前提交 PR,并确保 PR 能够被合并。逾期提交或提交失败的作业将不予评分。

Footnotes

  1. Create reaction for an issue comment

  2. What is the application/vnd.github+json media type? - Stack Overflow

  3. Creating a personal access token - GitHub Docs

@DarkHighness
Copy link
Contributor

51255903048
仓库链接:https://github.com/DarkHighness/darkhighness.github.io
报告链接:https://twiliness.site/2023/05/15/github-action/

@abcdabcd3899
Copy link
Contributor

abcdabcd3899 commented May 17, 2023

52265903006
仓库链接: https://github.com/abcdabcd3899/abcdabcd3899.github.io
报告链接: https://github.com/abcdabcd3899/abcdabcd3899.github.io/actions/runs/5002351065 https://abcdabcd3899.github.io/blog-post-3/

@yygs-yyss
Copy link
Contributor

51255903017
仓库链接:https://github.com/yygs-yyss/test_action
报告链接:https://yygs-yyss.github.io/2023/05/21/github_action/

@springyulu
Copy link
Contributor

51255903026
仓库链接:https://github.com/springyulu/test-action
报告链接:https://springyulu.github.io/2023/05/23/github-actions/

@lroethan
Copy link
Contributor

52265903002
仓库链接:https://github.com/lroethan/OSS-toy-action-example
报告链接:https://github.com/lroethan/OSS-toy-action-example/blob/master/README.md

@LinRS1999
Copy link
Contributor

51255903040
仓库链接:https://github.com/LinRS1999/test_action
报告链接:https://linrs1999.github.io/2023/05/23/github_action_demo/

@JinaoLiu
Copy link
Contributor

51255903038
仓库链接:https://github.com/JinaoLiu/JinaoLiu.github.io
报告链接:https://jinaoliu.github.io/2023/05/24/GitHub-Actions%E4%BD%BF%E7%94%A8/

@momentNi
Copy link
Contributor

51255903022
仓库链接:https://github.com/momentNi/momentni.github.io
报告链接:https://github.com/momentNi/momentni.github.io/blob/main/.github/workflows/README.md

@JackWeiw
Copy link

51255903048 仓库链接:https://github.com/DarkHighness/darkhighness.github.io 报告链接:https://twiliness.site/2023/05/15/github-action/

liao old NB!!!

@nicole01101101zke
Copy link
Contributor

51255903101
仓库链接:https://github.com/nicole01101101zke/Test-For-Github-Action
报告链接:https://nicole01101101zke.github.io/2023/05/Github-Actions%E6%8A%A5%E5%91%8A/

@tyxtyxtyxtyx
Copy link
Contributor

52265903007
仓库链接:https://github.com/tyxtyxtyxtyx/tyxtyxtyxtyx.github.io
报告链接:https://github.com/tyxtyxtyxtyx/tyxtyxtyxtyx.github.io/blob/main/readme.md

@Kongbaimoon
Copy link
Contributor

52265903009
仓库链接:https://github.com/Kongbaimoon/blog_hw
报告链接:https://github.com/Kongbaimoon/blog_hw/blob/main/action.md

@JackWeiw
Copy link

51255903105 仓库链接
报告链接

@TieWay59
Copy link
Member Author

TieWay59 commented Jun 20, 2023

共计 12 人次参与了报告评论

login 学号 仓库链接
DarkHighness 51255903048 仓库链接:https://github.com/DarkHighness/darkhighness.github.io
abcdabcd3899 52265903006 仓库链接: https://github.com/abcdabcd3899/abcdabcd3899.github.io
yygs-yyss 51255903017 仓库链接:https://github.com/yygs-yyss/test_action
springyulu 51255903026 仓库链接:https://github.com/springyulu/test-action
lroethan 52265903002 仓库链接:https://github.com/lroethan/OSS-toy-action-example
LinRS1999 51255903040 仓库链接:https://github.com/LinRS1999/test_action
JinaoLiu 51255903038 仓库链接:https://github.com/JinaoLiu/JinaoLiu.github.io
momentNi 51255903022 仓库链接:https://github.com/momentNi/momentni.github.io
nicole01101101zke 51255903101 仓库链接:https://github.com/nicole01101101zke/Test-For-Github-Action
tyxtyxtyxtyx 52265903007 仓库链接:https://github.com/tyxtyxtyxtyx/tyxtyxtyxtyx.github.io
Kongbaimoon 52265903009 仓库链接:https://github.com/Kongbaimoon/blog_hw
JackWeiw 51255903105 仓库链接:https://github.com/JackWeiw/JackWeiw.github.io

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests