Skip to content

Commit 34d26f0

Browse files
committed
👷 Remove guideline command.
- Separate Github community from guideline command - Separate Git flow from guideline command
1 parent d817bb6 commit 34d26f0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+235
-95
lines changed

built_in/git_flow.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
module Shift
2+
module BuiltIn
3+
class GitFlow
4+
5+
class ValidationError < ShiftError
6+
end
7+
8+
def self.execute(arguments)
9+
raise UnknownAction.new({message: "You should provide a valid action."}) unless !arguments[0].nil?
10+
case arguments[0]
11+
when :validate
12+
GitFlow.validate
13+
else
14+
raise UnknownAction.new({message: "Unknown action: #{arguments[0]}."})
15+
end
16+
end
17+
18+
def self.validate
19+
branches = BuiltIn::Sh.execute(["git branch -a"])
20+
raise ValidationError.new({message: "master branch is missing."}) if branches.match(/remotes\/origin\/master/).nil?
21+
raise ValidationError.new({message: "develop branch is missing."}) if branches.match(/remotes\/origin\/develop/).nil?
22+
non_git_flow_branches = branches.scan(/remotes\/origin\/(?!(feature|develop|master|release|hotfix))(.+)/)
23+
raise ValidationError.new({message: "The following branches are not compatible with Git flow: #{non_git_flow_branches.join(', ')}"}) if non_git_flow_branches.count > 0
24+
end
25+
end
26+
end
27+
end

built_in/github_community.rb

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
module Shift
2+
module BuiltIn
3+
class GithubCommunity
4+
5+
class UnknownAction < ShiftError
6+
end
7+
8+
class ValidationError < ShiftErrors
9+
end
10+
11+
def self.execute(arguments)
12+
raise UnknownAction.new({message: "You should provide a valid action."}) unless !arguments[0].nil?
13+
case arguments[0]
14+
when :validate
15+
GithubCommunity.validate
16+
else
17+
raise UnknownAction.new({message: "Unknown action: #{arguments[0]}."})
18+
end
19+
end
20+
21+
def self.validate
22+
errors = []
23+
errors.push({ severity: :error, message: "README.md is missing." }) if ! File.exists?("README.md")
24+
GithubCommunity.validate_markdown("README.md", errors) if File.exists?("README.md")
25+
errors.push({ severity: :error, message: "CONTRIBUTING.md is missing." }) if ! File.exists?("CONTRIBUTING.md")
26+
GithubCommunity.validate_markdown("CONTRIBUTING.md", errors) if File.exists?("CONTRIBUTING.md")
27+
errors.push({ severity: :warning, message: "MANIFESTO.md is missing." }) if ! File.exists?("MANIFESTO.md")
28+
GithubCommunity.validate_markdown("MANIFESTO.md", errors) if File.exists?("MANIFESTO.md")
29+
errors.push({ severity: :warning, message: "LICENSE is missing." }) if ! File.exists?("LICENSE")
30+
errors.push({ severity: :warning, message: "CODE_OF_CONDUCT.md is missing." }) if ! File.exists?("CODE_OF_CONDUCT.md")
31+
GithubCommunity.validate_markdown("CODE_OF_CONDUCT.md", errors) if File.exists?("CODE_OF_CONDUCT.md")
32+
errors.push({ severity: :error, message: ".github is missing." }) if ! Dir.exist?(".github")
33+
errors.push({ severity: :error, message: "ISSUE_TEMPLATE is missing." }) if ((! Dir.exist?(".github/ISSUE_TEMPLATE") || Dir.empty?(".github/ISSUE_TEMPLATE")) &&
34+
(! Dir.exist?(".github/issue_template") || Dir.empty?(".github/issue_template")) &&
35+
(! File.exists?(".github/ISSUE_TEMPLATE.md")) &&
36+
(! File.exists?(".github/issue_template.md")))
37+
errors.push({ severity: :error, message: "PULL_REQUEST_TEMPLATE is missing." }) if ((! Dir.exist?(".github/PULL_REQUEST_TEMPLATE") || Dir.empty?(".github/PULL_REQUEST_TEMPLATE")) &&
38+
(! Dir.exist?(".github/pull_request_template") || Dir.empty?(".github/pull_request_template")) &&
39+
(! File.exists?(".github/PULL_REQUEST_TEMPLATE.md")) &&
40+
(! File.exists?(".github/pull_request_template.md")))
41+
raise ValidationError.new(errors) if errors.count > 0
42+
end
43+
44+
private
45+
46+
def self.validate_markdown(file_path, errors)
47+
begin
48+
BuiltIn::Markdown.validate(file_path)
49+
rescue MarkdownError => markdown_error
50+
errors.push({ severity: :error, message: markdown_error.message })
51+
end
52+
end
53+
end
54+
end
55+
end

built_in/guideline.rb

Lines changed: 0 additions & 39 deletions
This file was deleted.

built_in/guideline/github_community.rb

Lines changed: 0 additions & 44 deletions
This file was deleted.

built_in/service.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def execute(built_in_name, arguments)
2424
end
2525

2626
def self.built_in_class_ref(built_in_name)
27-
class_name = "BuiltIn::" + built_in_name.capitalize
27+
class_name = "BuiltIn::" + built_in_name.shift_class
2828
begin
2929
return Shift.const_get(class_name)
3030
rescue NameError

built_in/sh.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def self.execute(arguments)
2020
exit_status = thread.value.exitstatus
2121
end
2222
raise BuiltInFailed.new(result) if exit_status != 0
23-
return true
23+
return result
2424
end
2525
end
2626
end

spec/git_flow/git_flow_spec.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
require_relative "../../shift"
2+
3+
mock_folder_name = "./spec/git_flow/mock"
4+
5+
describe Shift::ShiftCore, "a user want to validate the presence of Git flow" do
6+
context "with master branch missing" do
7+
it "should not execute the :beta lane" do
8+
core = Shift::ShiftCore.new
9+
folder = Shift::ShiftFolder.new(mock_folder_name, 'missing_master')
10+
expect { core.execute_lane(:beta, folder) }.to raise_error Shift::BuiltIn::GitFlow::ValidationError
11+
end
12+
end
13+
context "with develop branch missing" do
14+
it "should not execute the :beta lane" do
15+
core = Shift::ShiftCore.new
16+
folder = Shift::ShiftFolder.new(mock_folder_name, 'missing_develop')
17+
expect { core.execute_lane(:beta, folder) }.to raise_error Shift::BuiltIn::GitFlow::ValidationError
18+
end
19+
end
20+
context "with branch does not follow the Git flow standard" do
21+
it "should not execute the :beta lane" do
22+
core = Shift::ShiftCore.new
23+
folder = Shift::ShiftFolder.new(mock_folder_name, 'not_follow_git_flow_standard')
24+
expect { core.execute_lane(:beta, folder) }.to raise_error Shift::BuiltIn::GitFlow::ValidationError
25+
end
26+
end
27+
context "with all the branches follow the Git flow standard" do
28+
it "should execute the :beta lane" do
29+
core = Shift::ShiftCore.new
30+
folder = Shift::ShiftFolder.new(mock_folder_name, 'follow_git_flow_standard')
31+
expect { core.execute_lane(:beta, folder) }.not_to raise_error
32+
end
33+
end
34+
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
before_all do
2+
sh "rm -rf /tmp/follow_git_flow_standard"
3+
sh "mkdir /tmp/follow_git_flow_standard; cd /tmp/follow_git_flow_standard; git init; touch empty; git add .; git commit -m 'Initial commit'; git checkout -b remotes/origin/master; git checkout -b remotes/origin/develop; git checkout -b remotes/origin/feature/toto; git checkout -b remotes/origin/release/0.4.1; git checkout -b remotes/origin/hotfix/fix-ci"
4+
end
5+
6+
lane :beta do
7+
Dir.chdir("/tmp/follow_git_flow_standard") do
8+
git_flow :validate
9+
end
10+
end

spec/git_flow/mock/missing_develop

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
before_all do
2+
sh "rm -rf /tmp/missing_develop"
3+
sh "mkdir /tmp/missing_develop; cd /tmp/missing_develop; git init; touch empty; git add .; git commit -m 'Initial commit'; git checkout -b remotes/origin/master"
4+
end
5+
6+
lane :beta do
7+
Dir.chdir("/tmp/missing_develop") do
8+
git_flow :validate
9+
end
10+
end

spec/git_flow/mock/missing_master

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
before_all do
2+
sh "rm -rf /tmp/missing_master"
3+
sh "mkdir /tmp/missing_master; cd /tmp/missing_master; git init"
4+
end
5+
6+
lane :beta do
7+
Dir.chdir("/tmp/missing_master") do
8+
git_flow :validate
9+
end
10+
end

0 commit comments

Comments
 (0)