class Gitl::CreateTag
Public Class Methods
new(argv)
click to toggle source
Calls superclass method
# File lib/commands/create_tag.rb, line 25 def initialize(argv) @branch = argv.shift_argument @tag_name = argv.shift_argument @force = argv.flag?('force') super end
options()
click to toggle source
Calls superclass method
# File lib/commands/create_tag.rb, line 19 def self.options [ ["--force", "忽略tag是否存在,强制执行"], ].concat(super) end
Public Instance Methods
gitlab_search_project(project_name)
click to toggle source
# File lib/commands/create_tag.rb, line 85 def gitlab_search_project(project_name) projects = Gitlab.project_search(project_name) if projects.size > 1 info "find #{projects.size} project named #{project_name}. you means which one?" projects.each do |project| print project.name + ' ' end print "\n" raise Error.new("find #{projects.size} project named #{project_name}") elsif projects.size == 1 project = projects[0]; else raise Error.new("can't find project named '#{project_name}'.") end project end
run()
click to toggle source
# File lib/commands/create_tag.rb, line 42 def run # api: https://www.rubydoc.info/gems/gitlab/toplevel # document: https://narkoz.github.io/gitlab/cli Gitlab.configure do |config| # set an API endpoint # API endpoint URL, default: ENV['GITLAB_API_ENDPOINT'] config.endpoint = self.gitl_config.gitlab.endpoint # set a user private token # user's private token or OAuth2 access token, default: ENV['GITLAB_API_PRIVATE_TOKEN'] config.private_token = self.gitl_config.gitlab.private_token # user agent config.user_agent = "gitl ruby gem[#{VERSION}" end self.gitl_config.projects.each do |project| gitlab_project = gitlab_search_project(project.name) info "find project #{gitlab_project.name} on #{gitlab_project.web_url}." begin tag = Gitlab.tag(gitlab_project.id, @tag_name) rescue Gitlab::Error::NotFound => error tag = nil rescue Gitlab::Error::Error => error raise(error) end if tag.nil? Gitlab.create_tag(gitlab_project.id, @tag_name, @branch) info "create tag '#{@tag_name}' success" else if @force info "tag '#{@tag_name}' exist, skip." else help! "tag '#{@tag_name}' exist." end end puts end end
validate!()
click to toggle source
Calls superclass method
# File lib/commands/create_tag.rb, line 32 def validate! super if @branch.nil? help! 'branch is required.' end if @tag_name.nil? help! 'tag_name is required.' end end