Skip to content

Instantly share code, notes, and snippets.

@kaelig
Created October 12, 2022 08:24
Show Gist options
  • Save kaelig/7d89e02e79647f64057d129e75f1ff9c to your computer and use it in GitHub Desktop.
Save kaelig/7d89e02e79647f64057d129e75f1ff9c to your computer and use it in GitHub Desktop.
GitHub Action to nudge contributors to convert JavaScript files to TypeScript
on:
pull_request:
paths:
- '**.js'
- '**.jsx'
- '**.ts'
- '**.tsx'
name: TypeScript conversion nudge
jobs:
Nudge-to-convert-to-TypeScript-if-JavaScript-found:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: 🔎 List changed JavaScript files
id: changed-javascript-files
uses: tj-actions/changed-files@v32
with:
files: |
**/*.js
**/*.jsx
- name: 💬 Post comment to nudge contributor(s) to consider converting files to TypeScript
if: steps.changed-javascript-files.outputs.modified_files != '' || steps.changed-javascript-files.outputs.added_files != ''
uses: thollander/actions-comment-pull-request@v1
with:
message: 'This pull request adds or modifies JavaScript (`.js`, `.jsx`) files. Consider converting them to TypeScript.'
comment_includes: 'Consider converting them to TypeScript'
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: 🏷️ Add a label to the PR to help track how many pull requests adds or modifies JavaScript files
if: steps.changed-javascript-files.outputs.modified_files != '' || steps.changed-javascript-files.outputs.added_files != ''
uses: actions-ecosystem/action-add-labels@v1
with:
labels: 'Adds or modifies js files'
- name: 💬 Update the comment if JavaScript files were deleted or renamed to .ts / .tsx
if: contains(github.event.pull_request.labels.*.name, 'Adds or modifies js files') && steps.changed-javascript-files.outputs.modified_files == '' && steps.changed-javascript-files.outputs.added_files == ''
uses: thollander/actions-comment-pull-request@v1
with:
message: |
~This pull request adds or modifies JavaScript (`.js`, `.jsx`) files. Consider converting them to TypeScript.~
Thank you for converting JavaScript files to TypeScript 🎉"
comment_includes: 'Consider converting them to TypeScript'
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: 🏷️ Remove the label if JavaScript was converted
if: contains(github.event.pull_request.labels.*.name, 'Adds or modifies js files') && steps.changed-javascript-files.outputs.modified_files == '' && steps.changed-javascript-files.outputs.added_files == ''
uses: actions-ecosystem/action-remove-labels@v1
with:
labels: 'Adds or modifies js files'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment