GithubHelp home page GithubHelp logo

marocchino / checkbox-action Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 1.0 1.91 MB

Checks or unchecks a checkbox in the body of the pull request, or returns the list confirming the change in the checkbox.

License: MIT License

TypeScript 98.70% JavaScript 1.30%
checkbox github-actions pull-requests

checkbox-action's Introduction

checkbox-action status

Checkbox Action

It works in two main ways:

  1. Checks or unchecks a checkbox in the body of the pull request.
  2. Returns the list, confirming the change in the checkbox.

This library runs with GitHub Actions. If you feel that the example grammar below is not friendly enough, we recommend reading this page first.

Usage

I think the most common use is to visualize the results of CI execution, and here's an example.

  test: # make sure the action works on a clean machine without building
    runs-on: ubuntu-latest
    permissions:
      pull-requests: write
    steps:
      - uses: actions/checkout@v3
      - uses: marocchino/checkbox-action@v1
        with:
          list: 'test ok'
          action: 'uncheck'
          error: 'warn'
      - run: |
          yarn
      - run: |
          yarn all
      - uses: marocchino/checkbox-action@v1
        with:
          list: 'test ok'
          action: 'check'
          error: 'warn'

Here's an example of checking to see if a particular checkbox has been checked recently. Unchecking works the same way.

NOTE: I don't think detect will work again on events other than edit.

on:
  pull_request:
    types:
      - edited
jobs:
  detect:
    runs-on: ubuntu-latest
    outputs:
      checked: ${{ steps.detect.outputs.checked }}
    steps:
      - uses: marocchino/checkbox-action@v1
        id: detect
        with:
          action: 'detect'
  test:
    needs: detect
    if: ${{ contains(fromJSON(needs.detect.outputs.checked), 'trigger test') }}
    runs-on: ubuntu-latest
    steps:
      - run: echo Add your CI here

Inputs

action

Optional check, uncheck or detect. This default to 'check'

list

Optional However, one of the list and matches required when check, uncheck action. Line separated List of checkboxes to modify.

matches

Optional However, one of the list and matches required when check, uncheck action. Regular expression for the checkbox to modify.

error

Optional error, warn or ignore. Specifies whether to skip or raise an error when not found. This defaults to error

GITHUB_TOKEN

Optional The GitHub access token (e.g. secrets.GITHUB_TOKEN) used to update the body. This defaults to {{ github.token }}.

Outputs

Only available on detect action.

checked

Returns a list of checked items from the previous modification as json in []string.

unchecked

Returns a list of checked items from the previous modification as json in []string.

checkbox-action's People

Contributors

airtonix avatar dependabot[bot] avatar marocchino avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

airtonix

checkbox-action's Issues

doesn't report checkboxes that are always checked

If a Pr is built from a template, and that template starts any checkbox off as checked, then this action will only return those checkbox items if they are changed.

this action should probably change the output from

outputs = { checked, unchecked }

to

outputs = {
  changed: { checked, unchecked },
  checked, unchecked
}

so that it properly communicates the intent of the `getDiff` outputs.

Fails when the title is changed

Hello,

It looks like this action doesn't handle the case when only the pull request title is changed.

With this trigger the action can be run when the title or the description is changed:

on: 
  pull_request:
    types: [edited]

But when only the title is concerned it seems that the github.context.payload.changes.body variable (used here) is empty or absent (cf. docs).

Leading to this error:

Run marocchino/checkbox-action@03a47510e9dcd6931775838d362ec698bac07c16
  with:
    action: detect
    error: error
    GITHUB_TOKEN: ***
Error: Cannot read properties of undefined (reading 'from')

fails when pull_request is undefined

For some two functions attempting to get body are failing because github.context.payload.pull_request is undefined.

When the PR body hasn't changed from its original state, this function fails because changes.body.from doesn't exist on the context until changes are made to the PR body.

https://github.com/marocchino/checkbox-action/blob/main/src/detect.ts#L7

image

workflow:

name: Check PR title

on:
  pull_request_target:
    types:
      - opened
      - reopened
      - edited
      - synchronize

jobs:
  DetectCheckboxes:
    runs-on: ubuntu-latest
    outputs:
      checked: ${{ steps.detect.outputs.checked }}
    steps:
      - uses: marocchino/checkbox-action@v1
        id: detect
        with:
          action: 'detect'

  PrintCheckboxes:
    needs: DetectCheckboxes
    runs-on: ubuntu-latest
    steps:
      - run: |
          echo ${{needs.detect.outputs.checked}}

  LintPrTitle:
    runs-on: ubuntu-latest
    permissions:
      statuses: write
    steps:
      - uses: aslafy-z/conventional-pr-title-action@v3
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

The PR template :

# Description

## What kind of change is this?

- [ ] bug fix
- [ ] documentation
- [ ] new feature

## Steps to test changes

<!-- 
It's important that changes proposed are able to be verified by others.
Provide enough information for others to follow. Screenshots are welcome.
//-->

1. Build the app with `command to build`
2. Run the app with `./build/lamp --required-args`
3. Configure the app ...
4. Do this in the app ...
5. Then this ...
6. Observe this in the app ... to confirm changes.

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.