octokit / request-action

A GitHub Action to send arbitrary requests to GitHub's REST API
https://github.com/marketplace/actions/GitHub-API-Request
MIT License
370 stars 47 forks source link

[DOCS]: Example of required_status_checks on branch protection ON #234

Closed adrianioana closed 1 year ago

adrianioana commented 1 year ago

Describe the need

Hi team,

First of all, thank you for the efforts invested in creating this great action.

I am currently using the octokit/request-action@v2.x action to turn off & on the branch protection. See the example below:

steps:
- name: Checkout
  uses: actions/checkout@v3
  with:
    fetch-depth: 0
    ref: ${{ github.ref }}

- name: Branch protection OFF
  uses: octokit/request-action@v2.x
  with:
    route: PUT /repos/:repository/branches/develop/protection
    repository: ${{ github.repository }}
    required_status_checks: |
      null
    enforce_admins: |
      null
    required_pull_request_reviews: |
      null
    restrictions: | 
      null 
  env:
      GITHUB_TOKEN: ${{ secrets.PAT }}

- name: Commit
  run: |
      git add myfolder
      git config user.name "MyUsername"
      git config user.email "MyEmail"
      git commit -m 'MyCommitMessage'
      git push $REPOSITORY 

- name: Branch protection ON
  uses: octokit/request-action@v2.x
  with:
    route: PUT /repos/:repository/branches/develop/protection
    repository: ${{ github.repository }}
    required_status_checks: |
      null
    enforce_admins: |
      null
    required_pull_request_reviews: |
      dismiss_stale_reviews: false
      required_approving_review_count: 2
    restrictions: | 
      null 
  env:
      GITHUB_TOKEN: ${{ secrets.PAT }}

The action works perfectly but I would have a question on the required_status_checks property: Would you have an example on how to fill this field ? My required status check is called "Validate PR" and tried to add it in the Branch protection ON action as you can see below, but without any luck.

- name: Branch protection ON
  uses: octokit/request-action@v2.x
  with:
    route: PUT /repos/:repository/branches/develop/protection
    repository: ${{ github.repository }}
    required_status_checks: |
      Validate PR

also

    required_status_checks: |
      'Validate PR'

Pipeline logs:

Run octokit/request-action@v2.x with: route: PUT /repos/:repository/branches/develop/protection repository: MCBC-Org/beermate-salesforce required_status_checks: Validate PR

enforce_admins: null

required_pull_request_reviews: dismiss_stale_reviews: false

required_approving_review_count: 2

restrictions: null

mediaType: {}

env: GITHUB_TOKEN: *** PUT /repos/:repository/branches/develop/protection

enforce_admins: null mediaType: [object Object] repository: MCBC-Org/beermate-salesforce required_pull_request_reviews: [object Object] required_status_checks: Validate PR restrictions: null < 422 220ms Error: Invalid request.

No subschema in "anyOf" matched. For 'allOf/0', "Validate PR" is not an object. Not all subschemas of "allOf" matched. For 'anyOf/1', "Validate PR" is not a null.

SDK Version

No response

API Version

2.x

Relevant log output

No response

Code of Conduct

adrianioana commented 1 year ago

I will close the issue as I managed to resolve my challenge using: required_status_checks: | strict: false checks: [ { "context": "Validate Job", "app_id": null } ]