Making pull requests to a GitHub repository automatically with GitHub Actions

后端 未结 1 1858
半阙折子戏
半阙折子戏 2020-12-29 17:30

I have a file in a GitHub repository that needs updating occasionally by running a command.

As part of a GitHub Workflows, I want to have a bot running a command, an

相关标签:
1条回答
  • 2020-12-29 18:09

    I made a GitHub Action that I think will help you with this use case. https://github.com/peter-evans/create-pull-request

    create-pull-request action needs to be run in conjunction with other actions or steps that modify or add files to your repository. The changes will be automatically committed to a new branch and a pull request created.

    Here is an example that sets most of the main inputs.

    on:
      repository_dispatch:
        types: [create-pull-request]
    name: Create Pull Request
    jobs:
      createPullRequest:
        runs-on: ubuntu-latest
        steps:
          - uses: actions/checkout@v2
          - name: Create report file
            run: date +%s > report.txt
          - name: Create Pull Request
            uses: peter-evans/create-pull-request@v3
            with:
              token: ${{ secrets.GITHUB_TOKEN }}
              commit-message: Add report file
              committer: Peter Evans <peter-evans@users.noreply.github.com>
              body: |
                New report
                - Contains *today's* date
                - Auto-generated by [create-pull-request][1]
    
                [1]: https://github.com/peter-evans/create-pull-request
              title: '[Example] Add report file'
              labels: report, automated pr
              assignees: peter-evans
              reviewers: peter-evans
              milestone: 1
              branch: example-patches
    

    To make it bot-like you can trigger the workflow periodically.

    on:
     schedule:
       - cron: '*/5 * * * *'
    

    Alternatively, you can set the workflow to trigger via webhook, as in the example above.

    on:
      repository_dispatch:
        types: [create-pull-request]
    

    To trigger the workflow call the following. [username] is a GitHub username. [token] is a repo scoped token. [repository] is the name of the repository the workflow resides in.

    curl -XPOST -u "[username]:[token]" -H "Accept: application/vnd.github.everest-preview+json" -H "Content-Type: application/json" https://api.github.com/repos/[username]/[repository]/dispatches --data '{"event_type": "create-pull-request"}'
    

    For further examples check out the documentation here.

    0 讨论(0)
提交回复
热议问题