Skip to content
This repository has been archived by the owner on Apr 30, 2021. It is now read-only.

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
dawidd6 committed Sep 24, 2019
1 parent 05edd6b commit be1c0bb
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 49 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: test
34 changes: 7 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,14 @@
# action-delete-branch
# Delete branch Github Action

This action simply deletes a branch from origin repository
An action that simply deletes a branch from repository.

## Usage

```yaml
- uses: dawidd6/action-delete-branch@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Delete PR head branch
uses: dawidd6/action-delete-branch@master
with:
branch: xyz
```
```yaml
# works only if tested commit is referenced to pull request or issue
# PR_NUMBER is replaced by pull request number
- uses: dawidd6/action-delete-branch@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
branch: xyz-PR_NUMBER
be_kind: true
```
```yaml
# works only if tested commit is referenced to pull request or issue
# PR_HEAD_BRANCH is replaced by pull request head branch
- uses: dawidd6/action-delete-branch@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
branch: PR_HEAD_BRANCH
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.pull_request.head.ref }}
be_kind: true # don't fail on errors
```
21 changes: 13 additions & 8 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
name: 'delete-branch'
description: 'Delete branch'
author: 'dawidd6'
name: delete-branch
description: Delete branch
author: dawidd6
branding:
icon: git-branch
color: red
inputs:
github_token:
description: Github token
required: true
branch:
description: 'Branch name to delete'
description: Branch name to delete
required: true
default: ''
be_kind:
description: 'Be kind and do not scream if an exception occurs'
description: Be kind and do not scream if an exception occurs
required: false
default: false
runs:
using: 'docker'
image: 'Dockerfile'
using: docker
image: Dockerfile
18 changes: 4 additions & 14 deletions entrypoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,11 @@

# Github
repo = ENV["GITHUB_REPOSITORY"]
token = ENV["GITHUB_TOKEN"]
event_path = ENV["GITHUB_EVENT_PATH"]

# Event
json = File.read(event_path)
payload = JSON.parse(json)
pr = payload["pull_request"]
pr_number = pr["number"] unless pr.nil?
pr_head_branch = pr["head"]["ref"] unless pr.nil?

# Inputs
be_kind = ENV["INPUT_BE_KIND"]
branch = ENV["INPUT_BRANCH"]
branch = branch.sub("PR_NUMBER", pr_number.to_s) unless pr_number.nil?
branch = branch.sub("PR_HEAD_BRANCH", pr_head_branch.to_s) unless pr_head_branch.nil?
token = ENV["INPUT_GITHUB_TOKEN"]

# Main
begin
Expand All @@ -30,9 +20,9 @@
puts "==> Branch \"#{branch}\" deleted successfully"
else
puts "==> Branch \"#{branch}\" deletion failure"
exit(1)
exit(1) unless be_kind
end
rescue StandardError
puts "==> Branch \"#{branch}\" not found"
rescue StandardError => e
puts "==> Error: #{e.message}"
exit(1) unless be_kind
end

0 comments on commit be1c0bb

Please sign in to comment.