Skip to content
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.

Repo to be archived, but README doesn't provide full replacement #143

Open
theletterf opened this issue Jun 13, 2023 · 10 comments
Open

Repo to be archived, but README doesn't provide full replacement #143

theletterf opened this issue Jun 13, 2023 · 10 comments

Comments

@theletterf
Copy link
Contributor

The README example using gh pr create is incomplete. The pull-request action allowed to update existing sync PRs; this is not the case with gh pr create.

If the repo is going to be archived, will we be able to still use it? If not, what's a full replacement?

@theletterf theletterf changed the title Repo to be archive, but README doesn't provide full replacement Repo to be archived, but README doesn't provide full replacement Jun 13, 2023
@theletterf
Copy link
Contributor Author

@heiskr I initially replied in #137, but opened an issue because, well, this should somehow get better closure.

@heiskr
Copy link
Contributor

heiskr commented Jun 14, 2023

It looks like the CLI doesn't have an upsert, but something along the lines of gh pr create || gh pr edit I would think would work.

@theletterf
Copy link
Contributor Author

theletterf commented Jun 15, 2023

@heiskr Would something like this work the same?

gh pr edit -B main || gh pr create -l "sync" -B main --title "Pulling ${{ github.ref }} into main" -H ${{ secrets.INTERMEDIATE_BRANCH }} -b "This PR synchronizes the public and private docs repo."

@heiskr
Copy link
Contributor

heiskr commented Jun 15, 2023

I wonder if there's a nifty way in bash to share the arguments between the commands. It looks great to me though :) Pull request welcome

@theletterf
Copy link
Contributor Author

This comes from @kov in cli/cli#5792 (reply in thread). I'm not actually sure it's a full replacement of the functionality. Would be nice to confirm; otherwise, only a fully fledged action can be a proper substitute.

@heiskr
Copy link
Contributor

heiskr commented Jun 20, 2023

I'd think something like this could work, its two lines 🤷🏼

gh_pr_up() { gh pr create $* || gh pr edit $* }
gh_pr_up --title "A new pull request" --body "Something"

@theletterf
Copy link
Contributor Author

theletterf commented Jun 21, 2023

Submitted a patch in #144

@theletterf
Copy link
Contributor Author

theletterf commented Jun 21, 2023

This is what I was trying in my action:

gh pr edit -B main || gh pr create -l "sync" -B main --title "Pulling ${{ github.ref }} into main" -H ${{ secrets.INTERMEDIATE_BRANCH }} -b "This PR synchronizes the public and private docs repo."

Could it work like that?

@asteel-gsa
Copy link

Adding this here incase anyone wants to use it. I attempted to use ${{ github.event.number }} for the PR# but had no such luck. Github Actions [Bot] when authoring the PR cannot invoke subsequent workflow calls (which we use to generate our terraform plan) hence the addition of our pr-comment. See peter evans readme for more information.

However, I believe @heiskr answer would be the solution to edit the body of the pr when needed.

  pull-request:
    name: Create Pull Request
    needs: [check-commit]
    if: ${{ needs.check-commit.outputs.should_run != 'false' }}
    runs-on: ubuntu-latest
    outputs:
        pr_number: ${{ steps.pr-number.outputs.pull_request_number }}
    steps:
      - uses: actions/checkout@v3
      - name: Get Current Date
        id: date
        run: |
          echo "date=$(date +%Y-%m-%d)" >> $GITHUB_OUTPUT

      - name: Get Git Short Commit
        id: git-short
        run: |
          echo "short_sha=$(git rev-parse --short ${{ github.sha }})" >> $GITHUB_OUTPUT

      - name: Open Pull Request
        id: open-pr
        run: |
          gh pr create --label "label" --title "title" --body "body" --base base --head head

      - name: Get Pull Request Number
        id: pr-number
        run: echo "pull_request_number=$(gh pr view --json number -q .number || echo "")" >> $GITHUB_OUTPUT

      - name: Comment on Pull Request
        id: pr-comment
        run: |
          gh pr comment ${{ steps.pr-number.outputs.pull_request_number }} --body "body."

@theletterf
Copy link
Contributor Author

So, for my needs, turns out I don't need gh pr edit, as the repo-sync PR gets updated as the branch. The problem is that any subsequent scheduled run throws error 1 because the PR already exists. I'd like to capture that exception--any tip?

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

No branches or pull requests

3 participants