Class: GitReviewer::Command
- Inherits:
-
CLAide::Command
- Object
- CLAide::Command
- GitReviewer::Command
- Defined in:
- lib/gitreviewer/command.rb
Class Method Summary collapse
Instance Method Summary collapse
- #analyze ⇒ Object
-
#initialize(argv) ⇒ Command
constructor
A new instance of Command.
- #run ⇒ Object
Constructor Details
#initialize(argv) ⇒ Command
32 33 34 35 36 37 38 39 40 |
# File 'lib/gitreviewer/command.rb', line 32 def initialize(argv) @init = argv.flag?('init', false) @target = argv.option('target') @source = argv.option('source') @analyze_reviewer = argv.flag?('reviewer', false) = argv.flag?('author', false) @version = argv.flag?('version', false) super end |
Class Method Details
.options ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/gitreviewer/command.rb', line 22 def self. [ ['--init', 'Initialize the code review configuration file of the Git repository. It will generate a `.gitreviewer.yml` file if needed.'], ['--target', 'The target branch to be analyzed, which is the same as the target branch selected when creating a Merge Request or Pull Request.'], ['--source', 'Optional, if not specified, the default is the current branch pointed to by Git HEAD. The source branch to be analyzed, which is the same as the source branch selected when creating a Merge Request or Pull Request. '], ['--author', 'Only analyze relevant authors involved in code changes.'], ['--reviewer', 'Only analyze suggested reviewers for code changes.'], ].concat(super) end |
Instance Method Details
#analyze ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/gitreviewer/command.rb', line 66 def analyze # 检查环境 if !Checker.is_git_repository_exist? Printer.red "Error: git repository not exist. Please execute the command in the root director of a git repository." exit 1 end # 检查参数 if ! && !@analyze_reviewer # 如果两个选项均没有,则默认分析作者和审查者 = true @analyze_reviewer = true end # 设置默认分支 if @source == nil # 默认 source 为当前分支 @source = Checker.current_git_branch end if @target == nil Printer.red "Error: target branch cannot be nil or empty. Please use `--target=<branch>` to specify the target branch." exit 1 end # 检查分支 if @source != nil && @target != nil # source 分支 if !Checker.is_git_branch_exist?(@source) Printer.red "Error: source branch `#{@source}` not exist." exit 1 end # target 分支 if !Checker.is_git_branch_exist?(@target) Printer.red "Error: target branch `#{@target}` not exist." exit 1 end # source、target 判重 if @source == @target Printer.red "Error: source branch and target branch should not be the same." exit 1 end end # 执行分析 analyzeOption = AnalyzeOption.new(@source, @target, , @analyze_reviewer, @verbose) analyzeOption.execute end |
#run ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/gitreviewer/command.rb', line 42 def run # 处理 help 选项 if @help_arg help! return end # 处理 version 选项 if @version Printer.put "git-reviewer #{GitReviewer::VERSION}" return end # 处理 init 选项 if @init initOption = InitOption.new initOption.execute return end # 分析 analyze end |