Skip to content

Commit b57c127

Browse files
Merge branch 'master' of github.com:devmasx/merge-branch
2 parents edcc101 + b2a56f9 commit b57c127

File tree

6 files changed

+55
-8
lines changed

6 files changed

+55
-8
lines changed

README.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,32 @@ jobs:
2020
steps:
2121
- uses: actions/checkout@master
2222
- name: Merge by labeled
23-
uses: devmasx/merge-branch@v1.0.0
23+
uses: devmasx/merge-branch@v1.1.0
2424
with:
2525
label_name: 'merged in develop'
2626
target_branch: 'develop'
2727
env:
2828
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
2929
```
30+
31+
## On any github event
32+
33+
```yaml
34+
name: Merge staging branch to uat
35+
on:
36+
push:
37+
branches:
38+
- 'staging'
39+
jobs:
40+
merge-branch:
41+
runs-on: ubuntu-latest
42+
steps:
43+
- uses: actions/checkout@master
44+
- name: Merge to uat branch
45+
uses: devmasx/[email protected]
46+
with:
47+
type: now
48+
target_branch: 'uat'
49+
env:
50+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
51+
```

action.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
name: 'Merge branch'
22
description: 'A GitHub Action that merge PR branch to other branchs'
33
author: Miguel Savignano
4+
inputs:
5+
type:
6+
type: 'labeled | now'
7+
required: false
8+
default: 'labeled'
9+
label_name:
10+
description: 'PR Label name'
11+
required: false
12+
target_branch:
13+
description: 'The name of target branch to merge'
14+
required: true
415
runs:
516
using: 'docker'
617
image: 'Dockerfile'

lib/adapters/push_adapter.rb renamed to lib/adapters/now_adapter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class PushAdapter
1+
class NowAdapter
22
def initialize(github_event, target_branch)
33
@event = github_event
44
@target_branch = target_branch

lib/index.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
@github_token = ENV['GITHUB_TOKEN']
99
@target_branch = ENV['INPUT_TARGET_BRANCH']
1010
@label_name = ENV['INPUT_LABEL_NAME']
11-
@type = ENV['INPUT_TYPE'] || 'labeled' # labeled | comment | push
11+
@type = ENV['INPUT_TYPE'] || 'labeled' # labeled | comment | now
1212

1313
service = MergeBrachService.new(
1414
event: @event, type: @type, target_branch: @target_branch, label_name: @label_name

lib/services/merge_branch_service.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
require_relative '../adapters/labeled_adapter'
2-
require_relative '../adapters/push_adapter'
2+
require_relative '../adapters/now_adapter'
33

44
class MergeBrachService
55

66
def initialize(inputs)
77
@inputs = inputs
8+
@inputs[:type] = 'labeled' unless @inputs[:type]
89
end
910

1011
def ensure_target_branch
@@ -20,10 +21,12 @@ def ensure_target_branch
2021

2122
def build_adapter
2223
case @inputs[:type]
23-
when 'push'
24-
PushAdapter.new(@inputs[:event], @inputs[:target_branch])
24+
when 'now'
25+
NowAdapter.new(@inputs[:event], @inputs[:target_branch])
2526
when 'labeled'
2627
LabeledAdapter.new(@inputs[:event], @inputs[:target_branch], @inputs[:label_name])
28+
else
29+
raise "Invalid type #{@inputs[:type]}"
2730
end
2831
end
2932
end

spec/merge_brach_service_spec.rb

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
require_relative '../lib/services/merge_branch_service'
22

33
describe MergeBrachService do
4+
context "with invalid type" do
5+
let(:inputs) {
6+
{ type: 'invalid_type', event: {}, target_branch: 'develop' }
7+
}
8+
9+
it "#target_branch" do
10+
service = MergeBrachService.new(inputs)
11+
expect{ service.ensure_target_branch }.to raise_error()
12+
end
13+
end
14+
415
context "with push" do
516
let(:target_branch) { 'develop' }
617
let(:inputs) {
7-
{ type: 'push', event: {}, target_branch: target_branch }
18+
{ type: 'now', event: {}, target_branch: target_branch }
819
}
920

1021
it "#target_branch" do
@@ -18,7 +29,7 @@
1829
let(:target_branch) { 'develop' }
1930
let(:event) { { 'action' => 'labeled', 'label' => { 'name' => label_name } } }
2031
let(:inputs) {
21-
{ type: 'labeled', event: event, target_branch: target_branch, label_name: label_name }
32+
{ event: event, target_branch: target_branch, label_name: label_name }
2233
}
2334

2435
context "match label" do

0 commit comments

Comments
 (0)