티스토리 뷰

반응형

우선 여기를 보고 github token을 만들어주세요..! (secrets.GITHUB_TOKEN을 써야해서 필요합니다.)

 

https://github.com/sdras/awesome-actions

 

이 중, actions/github-script 를 사용해서 아주 간편하게 github API를 사용할 수 있어요

(여기서 제공하는 github과 context라는 변수를 이용해서!!!)

 

만약에 저것을 안쓰고 githubAPI에 요청한다면, 이런식으로 스텝을 만들어줘야하는데,

- name: Create issue using REST API
  run: |
    curl --request POST \
    --url https://api.github.com/repos/${{ github.repository }}/issues \
    --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
    --header 'content-type: application/json' \
    --data '{
      "title": "Automated issue for commit: ${{ github.sha }}",
      "body": "This issue was automatically created by the GitHub Action workflow **${{ github.workflow }}**. \n\n The commit hash was: _${{ github.sha }}_."
      }'

 

github-script를 쓰면 이렇게 훨씬 간편하게 스텝을 만들어줄 수 있다는 것입니다...!!! 

  - name: create comment on issue
    uses: actions/github-script@v2
    with:
      github-token: ${{secrets.GITHUB_TOKEN}}
      script: |
        github.issues.createComment({
          issue_number: context.issue.number,
          owner: context.repo.owner,
          repo: context.repo.repo,
          body: '👋 Thanks for reporting!'
        })

 

 

참고로 run은 직접 짠 명령을 돌릴때,

uses는 외부(마켓플레이스)에서 짠 명령을 돌릴때 사용하는 키값입니다. 

 

github은 octokit/rest.js  객체이고

context는 context of the workflow run 객체 입니다. 

 

 

[1] Pull Request 

 

1) 테스트가 실패하면 comment를 남기고 PR을 클로즈하기

 

여기 를 보고 따라했습니다. 

(await 빼도 잘 동작하는데, 자바스크립트 잘 몰라서 넣어뒀습니다)

(... 이 뭔지는 모르겠어요)

 

 

 

 

 

 

참고로 테스트가 실패했을때, PR를 클로즈하는 게 아니라 머지만 안되게 막고 싶다면

github setting에 가서 이렇게 해주면 됩니다. (깃헙액션스 필요없음)

 

Workflow를 한 번 돌려줘야지 build and test가 나온다고 합니다.  (build and test는 저의 테스트 돌리는 스텝 이름입니다.)

 

 

 

⚠️ 안되는 것 ⚠️

 

1) 내가 approve하지 않은 open된 PR만 가져오기 

 

이렇게 open된 PR 리스트를 가져올 수 있는데,

approve관련 파라미터가 없음. 

- name: get pr list
  uses: actions/github-script@0.2.0
  with:
      github-token: ${{secrets.GITHUB_TOKEN}}
      script: |
        const pull_list = await github.pulls.list({
          owner: context.repo.owner,
          repo: context.repo.repo,
          state: "open"
        });

        console.log(pull_list)

 

파라미터는 이게 전부임.

 

 

2)  PR하면 reviewer 요청해주기

 

옥토킷에는 이 함수가 있는데,

 

 

이렇게 액션스에 해주면 requestReviewers가 없는 함수라고 나옴. ("github.pulls.requestReviewers is not a function" 이라는 에러메세지)

reviewers에 지금은 나의 아이디 넣어뒀는데, 실제로는 팀원들 아이디가 들어갈 것..!

- name: request reviewers
  uses: actions/github-script@0.2.0
  with:
      github-token: ${{secrets.GITHUB_TOKEN}}
      script: |
        const ref = "${{github.ref}}"
        const pull_number = Number(ref.split("/")[2])

        github.pulls.requestReviewers({
          owner: context.repo.owner,
          repo: context.repo.repo,
          pull_number: pull_number,
          reviewers: ["eunjin3786"]
        });

 

옥토킷에는 있는데 왜 안되는 것인지 모르겠음-!! 

 

 

+ 풀리퀘스트에 라벨 달고 싶다면 actions/labeler 쓰면 되는 것 같아요

 

 

🕶 마켓플레이스에 있는 것들 중 괜찮아보이는 것 🕶

 

여기 서 보았습니다.

 

[2] Issue

 

1) issue가 생기면 코멘트랑 라벨을 달아주기

 

 

 

 

 

굳이 필요없는 것 같은데 issue로 제보해준 분께 감사의 표현..? 할 수 있겠습니다

참고로 라벨은 여기에 붙게 됩니다.

 

 

 

Reference

github.com/sdras/awesome-actions

 

sdras/awesome-actions

A curated list of awesome actions to use on GitHub - sdras/awesome-actions

github.com

developer.github.com/v3/pulls/#list-pull-requests

 

Pull Requests

Get started with one of our guides, or jump straight into the API documentation.

developer.github.com

 

octokit.github.io/rest.js/v18#pulls-request-reviewers

 

octokit/rest.js

 

octokit.github.io

 

반응형
댓글