Skip to content

Commit

Permalink
Merge branch 'master' of github.com:devmasx/merge-branch
Browse files Browse the repository at this point in the history
  • Loading branch information
MiguelSavignano committed Nov 27, 2019
2 parents edcc101 + b2a56f9 commit b57c127
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 8 deletions.
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,32 @@ jobs:
steps:
- uses: actions/checkout@master
- name: Merge by labeled
uses: devmasx/merge-branch@v1.0.0
uses: devmasx/merge-branch@v1.1.0
with:
label_name: 'merged in develop'
target_branch: 'develop'
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
```
## On any github event
```yaml
name: Merge staging branch to uat
on:
push:
branches:
- 'staging'
jobs:
merge-branch:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Merge to uat branch
uses: devmasx/[email protected]
with:
type: now
target_branch: 'uat'
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
```
11 changes: 11 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
name: 'Merge branch'
description: 'A GitHub Action that merge PR branch to other branchs'
author: Miguel Savignano
inputs:
type:
type: 'labeled | now'
required: false
default: 'labeled'
label_name:
description: 'PR Label name'
required: false
target_branch:
description: 'The name of target branch to merge'
required: true
runs:
using: 'docker'
image: 'Dockerfile'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class PushAdapter
class NowAdapter
def initialize(github_event, target_branch)
@event = github_event
@target_branch = target_branch
Expand Down
2 changes: 1 addition & 1 deletion lib/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@github_token = ENV['GITHUB_TOKEN']
@target_branch = ENV['INPUT_TARGET_BRANCH']
@label_name = ENV['INPUT_LABEL_NAME']
@type = ENV['INPUT_TYPE'] || 'labeled' # labeled | comment | push
@type = ENV['INPUT_TYPE'] || 'labeled' # labeled | comment | now

service = MergeBrachService.new(
event: @event, type: @type, target_branch: @target_branch, label_name: @label_name
Expand Down
9 changes: 6 additions & 3 deletions lib/services/merge_branch_service.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
require_relative '../adapters/labeled_adapter'
require_relative '../adapters/push_adapter'
require_relative '../adapters/now_adapter'

class MergeBrachService

def initialize(inputs)
@inputs = inputs
@inputs[:type] = 'labeled' unless @inputs[:type]
end

def ensure_target_branch
Expand All @@ -20,10 +21,12 @@ def ensure_target_branch

def build_adapter
case @inputs[:type]
when 'push'
PushAdapter.new(@inputs[:event], @inputs[:target_branch])
when 'now'
NowAdapter.new(@inputs[:event], @inputs[:target_branch])
when 'labeled'
LabeledAdapter.new(@inputs[:event], @inputs[:target_branch], @inputs[:label_name])
else
raise "Invalid type #{@inputs[:type]}"
end
end
end
15 changes: 13 additions & 2 deletions spec/merge_brach_service_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
require_relative '../lib/services/merge_branch_service'

describe MergeBrachService do
context "with invalid type" do
let(:inputs) {
{ type: 'invalid_type', event: {}, target_branch: 'develop' }
}

it "#target_branch" do
service = MergeBrachService.new(inputs)
expect{ service.ensure_target_branch }.to raise_error()
end
end

context "with push" do
let(:target_branch) { 'develop' }
let(:inputs) {
{ type: 'push', event: {}, target_branch: target_branch }
{ type: 'now', event: {}, target_branch: target_branch }
}

it "#target_branch" do
Expand All @@ -18,7 +29,7 @@
let(:target_branch) { 'develop' }
let(:event) { { 'action' => 'labeled', 'label' => { 'name' => label_name } } }
let(:inputs) {
{ type: 'labeled', event: event, target_branch: target_branch, label_name: label_name }
{ event: event, target_branch: target_branch, label_name: label_name }
}

context "match label" do
Expand Down

0 comments on commit b57c127

Please sign in to comment.