Skip to content

Commit

Permalink
created pswh,dockerfile,action and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
ShivamHS committed Jun 27, 2024
0 parents commit 19e2e52
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM mcr.microsoft.com/dotnet/sdk:5.0-alpine3.13

COPY pr-naming.ps1 /

ENTRYPOINT [ "pwsh", "-File", "/pr-naming.ps1"]
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# PR Naming
This will take care of your PR naming, if it is matched with the regex pattern you have given or not

# Example
```yaml
name: Delete Tag

on:
pull_request:
types: [opened, synchronize, reopened, edited]
branches:
- master

jobs:
pr-title-check::
runs-on: windows-latest

steps:

- name: Check PR title format
uses: ShivamHS/PR-naming@v1.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
repo: your-repo-name
owner: repo-owner
pattern: enter the regex pattern for validation
30 changes: 30 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: 'PR Nomencleture'

description: 'Checks if PR is named as per input pattern'
author: Shivam
branding:
icon: clipboard
color: blue

inputs:
token:
description: 'GitHub token with repo scope.'
required: true
owner:
description: 'owner of repo.'
required: true
repo:
description: 'The name of the repository.'
required: true
pattern:
description: 'Keyword to match for deletion.'
required: true

runs:
using: docker
image: Dockerfile
args:
- ${{ inputs.token }}
- ${{ inputs.owner }}
- ${{ inputs.repo }}
- ${{ inputs.pattern }}
26 changes: 26 additions & 0 deletions pr-naming.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

param (
[string]$Token = $env:INPUT_TOKEN,
[string]$Owner = $env:INPUT_OWNER,
[string]$Repo = $env:INPUT_REPO,
[string]$Pattern = $env:INPUT_PATTERN
)


$headers = @{
Authorization = "Bearer $Token"
}

Write-Host "$Token, $Owner, $Pattern, $Repo"

$prUrl = "https://api.github.com/repos/$Owner/$Repo/pulls"
$prs = Invoke-RestMethod -Uri $prUrl -Headers $headers

foreach ($pr in $prs) {
$prTitle = $pr.title
if ($prTitle -match $Pattern) {
Write-Host "PR #$($pr.number): Title is valid: $prTitle"
} else {
Write-Host "PR #$($pr.number): Invalid title: $prTitle"
}
}

0 comments on commit 19e2e52

Please sign in to comment.