Giter Site home page Giter Site logo

pr-description's Introduction

Update Pull Request Description

GitHub action to append or replace text in a pull request description.

Gitmoji

Usage

This action supports pull_request and push events (where the push event ocurred on a branch with an open pull request).

Inputs

  • content: The content to append or replace in the PR body. Can be raw text or a file path. If a file path is provided, contentIsFilePath must be set to "true".
  • contentIsFilePath: Whether the content input is a file path. Defaults to "false".
  • regex: The regex to match against the PR body and replace with content. Defaults to "---.*".
  • regexFlags: The regex flags to use. Defaults to "".
  • appendContentOnMatchOnly: Whether to skip appending the content to the PR body if no regex matches are found. Defaults to "false".
  • token: The GitHub token to use.

Note: append mode is the default behavior when no regex match is found for backwards compatibility with existing action users. This may change in future minor/major versions and will be noted in the changelog.

Example Workflows

  • Simple replace all text in the PR description with Hello there!:

    on:
        pull_request:
    
    jobs:
        update-pr-description:
            runs-on: ubuntu-latest
            steps:
                - name: Checkout
                  uses: actions/checkout@v4
                - name: Update PR Description
                  uses: nefrob/[email protected]
                  with:
                      content: "Hello there!"
                      regex: ".*"
                      regexFlags: s
                      token: ${{ secrets.GITHUB_TOKEN }}

    Body before:

    Existing
    Body

    Body after:

    Hello there!
  • Reading from a file:

    on:
        pull_request:
    
    jobs:
        update-pr-description:
            runs-on: ubuntu-latest
            steps:
                - name: Checkout
                  uses: actions/checkout@v4
                - name: Update PR Description
                  uses: nefrob/[email protected]
                  with:
                      content: path/to/file.txt
                      contentIsFilePath: true
                      token: ${{ secrets.GITHUB_TOKEN }}

    File content:

    Hello there!
    

    Body before:

    Existing body

    Body after:

    Hello there!
  • Replace text in between comments:

    on:
        pull_request:
    
    jobs:
        update-pr-description:
            runs-on: ubuntu-latest
            steps:
                - name: Checkout
                  uses: actions/checkout@v3
                - name: Update PR Description
                  uses: nefrob/[email protected]
                  with:
                      content: "<!-- start match -->\nHello there!\n<!-- end match -->"
                      regex: "<!-- start match -->.*?<!-- end match -->"
                      regexFlags: ims
                      token: ${{ secrets.GITHUB_TOKEN }}

    Body before:

    <!-- start match -->
    Anything in between these comments will be replaced by a push to the PR.
    <!-- end match -->
    

    Body after:

    <!-- start match -->
    Hello there!
    <!-- end match -->
    

    This is particularly useful when paired with a pull_request_template.md that includes comments like these for automatic updates on every PR.

pr-description's People

Contributors

nefrob avatar

Stargazers

omar avatar Elias Krontiris avatar Dave avatar Chris Hough avatar  avatar

Watchers

 avatar

pr-description's Issues

Appending doesn't work when regex contains multiline

Describe the bug
Appending doesn't work when regex contains multiline.

#8 has been closed due to inactivity, but it still persists.

To Reproduce

Add following step to github action:

            - name: Update PR Description
              uses: nefrob/[email protected]
              with:
                  content: "<!-- start regex match -->Test\ntest\ntest<!-- end regex match -->"
                  regex: "<!-- start regex match -->.*?<!-- end regex match -->"
                  token: ${{ secrets.GITHUB_TOKEN }}

and run it several times. The issue results in multiple <!-- start regex match -->Test\ntest\ntest<!-- end regex match --> occurences, each appended to the previous one.

## Title
Hello there!
This change is about something entirely new. 

### More info
New line written manually. 
Also new line written manually...<!-- start regex match -->Test
test
test<!-- end regex match --><!-- start regex match -->Test
test
test<!-- end regex match --><!-- start regex match -->Test
test
test<!-- end regex match --><!-- start regex match -->Test
test
test<!-- end regex match -->

Expected behavior
I expect PR description to NOT be modified, since I am replacing value with the same value.

Screenshots
image

Additional info
What I've also observed, is that when you skip "end" regex match, like this:

            - name: Update PR Description
              uses: nefrob/[email protected]
              with:
                  content: "<!-- start regex match -->Test\ntest\ntest"
                  regex: "<!-- start regex match -->.*"
                  token: ${{ secrets.GITHUB_TOKEN }}

and run it multiple times, it doesn't just append the content, but replaces the first occurence of regex match until newline sign (so replaces <!-- start regex match -->Test with <!-- start regex match -->Test\ntest\ntest.

Running the action 3 times results in following:

...
Also new line written manually...<!-- start regex match -->Test
test
test
test
test
test
test

Add unit tests

Add some unit testing to increase confidence in the action code.

How do you add newlines with this action?

Usage

 - name: Sets resolver text
        uses: nefrob/[email protected]
        with:
          content: "${{ github.event.pull_request.body }}\n\nFixes AB#${{ steps.extract_itemid.outputs.itemid }}"
          token: ${{ secrets.GITHUB_TOKEN }}

Expected out would be an appended text string with two newlines.

this is the PR description.

Fixes AD#123

But the "\n" are completely ignored
The text ends up like the following

this is the PR description.Fixes AD#123

pull_request.number is undefined

There seems to be an issue with getting the PR number when force-pushing.

My action trigger is:

on:
    pull_request:
        types: [labeled]

When I force-push to a PR with a label on it. I get this error:

/home/runner/work/_actions/nefrob/pr-description/v1.0.0/dist/index.js:9014
  const prNumber = github.context.payload.pull_request.number;
                                                       ^

TypeError: Cannot read properties of undefined (reading 'number')
    at run (/home/runner/work/_actions/nefrob/pr-description/v1.0.0/dist/index.js:9014:56)

Docs: `appendContentOnMatchOnly` unclear

I'm using the action to replace placeholders in PR descriptions, and I was surprised when it appended those replacements to the end of the description when there were no regex matches found.

Ideally, replace-only-if-found would be the default, and a positive flag like appendIfNoMatch would control appending. Otherwise, I think it would help to document the appendContentOnMatchOnly option by describing its effect instead of the opposite of its effect. Current docs:

appendContentOnMatchOnly: Whether to append the content to the PR body if no matches are found. Defaults to "false".

It does control that behavior, but the way it's documented, it sounds like the default is not to append when no matches are found, which is not how it works. The default is to append when no matches are found, and true disables the append. I'd suggest something more like:

appendContentOnMatchOnly: Skip appending content if no regex matches are found. Defaults to "false".

Latest updates break action

Running this action against the latest master branch results in the following:

Run nefrob/pr-description@master
  with:
    content: ./notes.txt
    contentIsFilePath: true
    regex: [\s\S]+
    regexFlags: g
    token: REDACTED
    appendContentOnMatchOnly: false
  env:
    HUSKY_SKIP_INSTALL: true
    HUSKY: 0
/home/runner/work/_actions/nefrob/pr-description/master/dist/index.js:[3](https://github.com/REDACTED/actions/runs/6577213171/job/17868365686#step:4:3)118[5](https://github.com/REDACTED/actions/runs/6577213171/job/17868365686#step:4:5)
run().catch((error) => _actions_github__WEBPACK_IMPORTED_MODULE_0__.setFailed(error.message));
                                                                    ^

TypeError: _actions_github__WEBPACK_IMPORTED_MODULE_0__.setFailed is not a function
    at /home/runner/work/_actions/nefrob/pr-description/master/dist/index.js:31185:[6](https://github.com/REDACTED/actions/runs/6577213171/job/17868365686#step:4:6)[9](https://github.com/REDACTED/actions/runs/6577213171/job/17868365686#step:4:9)

Create release with Node20

Hello,

First of all thank you for creating and maintaining this action.
You have already implement the use of Node 20. But it is not part of any explicit release.
Could you please create a release that features Node 20?

I am following your example to replace the description but it always appends on new commits

my Pull request template

<!-- Description start-->
description goes here
<!-- Description end -->

my github action:

name: DEV | Update PR description

on:
  pull_request:
    branches:
      - main
    types: [opened, synchronize]

permissions:
  pull-requests: write
  contents: write

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Override PR description
        uses: nefrob/[email protected]
        with:
          content: |
            <!-- Description start-->
            ## Describe your changes

            ## Issue ticket number and link

            ## Checklist before requesting a review
            - [ ] I have performed a self-review of my code
            - [ ] I have tested my changes locally
            - [ ] I have ran pulumi up for my infra changes with prod profile
            - [ ] I have updated the database tables with the new changes
            - [ ] I have updated the environment variables and secrets  
            - [ ] I have applied the manual cluster changes if any
            - [ ] I have updated the dns configuration if any
            - [ ] I have updated the integrations settings if any

            ## Any comments/requests for reviewer?

            ### Please follow this [review ladder](https://www.netlify.com/blog/2020/03/05/feedback-ladders-how-we-encode-code-reviews-at-netlify/) for code reviews
            <!-- Description end -->

          regex: "<!-- Description start-->.*?<!-- Description end-->"
          regexFlags: ims

          token: ${{ secrets.GITHUB_TOKEN }}

As soon as a new commit is added to the PR, here is what my description looks like:

<!-- Description start-->
## Describe your changes

## Issue ticket number and link

## Checklist before requesting a review
- [x] I have performed a self-review of my code
- [x] I have tested my changes locally
- [ ] I have ran pulumi up for my infra changes with prod profile
- [ ] I have updated the database tables with the new changes
- [ ] I have updated the environment variables and secrets  
- [ ] I have applied the manual cluster changes if any
- [ ] I have updated the dns configuration if any
- [ ] I have updated the integrations settings if any

## Any comments/requests for reviewer?

### Please follow this [review ladder](https://www.netlify.com/blog/2020/03/05/feedback-ladders-how-we-encode-code-reviews-at-netlify/) for code reviews
<!-- Description end --><!-- Description start-->
## Describe your changes

## Issue ticket number and link

## Checklist before requesting a review
- [ ] I have performed a self-review of my code
- [ ] I have tested my changes locally
- [ ] I have ran pulumi up for my infra changes with prod profile
- [ ] I have updated the database tables with the new changes
- [ ] I have updated the environment variables and secrets  
- [ ] I have applied the manual cluster changes if any
- [ ] I have updated the dns configuration if any
- [ ] I have updated the integrations settings if any

## Any comments/requests for reviewer?

### Please follow this [review ladder](https://www.netlify.com/blog/2020/03/05/feedback-ladders-how-we-encode-code-reviews-at-netlify/) for code reviews
<!-- Description end -->

appendContentOnMatchOnly is not a valid input

What's happening

I'm following the docs and did:

name: "Update PR description"

on:
  pull_request:

jobs:
  update-pr-description:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3
      - name: Do action
        uses: nefrob/[email protected]
        with:
          content: ${{github.event.number}}
          regex: "PR_NUMBER"
          regexFlags: i
          token: ${{ secrets.GITHUB_TOKEN }}
          appendContentOnMatchOnly: true      <---- here

which resulted in:

image

Also, my content is appended to the description even with the property true

Expected:

The property should work.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.