Repository navigation
Expand file tree
/
Copy pathproject.rb
More file actions
89 lines (81 loc) · 3.94 KB
/
Copy pathproject.rb
File metadata and controls
89 lines (81 loc) · 3.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
module GitlabCli
module Command
class Project < Thor
def self.banner(task, namespace = true, subcommand = true)
"#{basename} #{task.formatted_usage(self, true, subcommand)}"
end
## ADD
desc "add [PROJECT_NAME] [OPTIONS]", "add a project"
long_desc <<-D
Add a project. The only required parameter is the project name
D
option :description, :desc => "The project's description", :type => :string, :aliases => ["-d"]
option :branch, :desc => "The project's default branch", :type => :string, :aliases => ["-b"]
option :namespace_id, :desc => "The namespace ID this project should be added to. Namespace ID is synonymous with group ID", :type => :string, :aliases => ["-g","-n"]
option :issues, :desc => "Enable issues for the project", :type => :boolean
option :wall, :desc => "Enable issues for the project", :type => :boolean
option :merge_requests, :desc => "Enable merge_requests for the project", :type => :boolean
option :wiki, :desc => "Enable wiki for the project", :type => :boolean
option :snippets, :desc => "Enable snippets for the project", :type => :boolean
def add(project_name)
ui = GitlabCli.ui
begin
project = GitlabCli::Util::Project.create project_name, options['description'], options['branch'], options['namespace_id'], options['issues'], options['merge_requests'], options['wall'], options['wiki'], options['snippets']
rescue ResponseCodeException => e
case e.response_code
when 404
ui.error "A project with this name already exists. Please choose a new name"
else
ui.error "Unable to create project \'%s\'" % [project_name]
ui.handle_error e
end
rescue Exception => e
ui.error "Unable to create project \'%s\'" % [project_name]
ui.handle_error e
else
ui.success "Project \"%s\" created successfully" % [project.name]
ui.info "ID: %s" % [project.id]
ui.info "URL: %s" % [project.project_url]
end
end
## INFO
desc "info [PROJECT]", "view detailed info for a project"
long_desc <<-D
View detailed information about a project.\n
[PROJECT] may be specified as [NAMESPACE]/[PROJECT] or [PROJECT_ID]. Use 'gitlab projects' to see a list of projects with their namespace and id.
D
def info(project_id)
ui = GitlabCli.ui
begin
project = GitlabCli::Util::Project.get(project_id)
rescue ResponseCodeException => e
case e.response_code
when 404
ui.error "Unable to get project info"
ui.error "Cannot find project with name or ID \"%s\"" % [project_id]
else
ui.error "Unable to get project info"
ui.handle_error e
end
rescue Exception => e
ui.error "Unable to get project info"
ui.handle_error e
else
ui.info "Project ID: %s" % [project.id]
ui.info "Name: %s" % [project.name]
ui.info "Path w/ Namespace: %s" % [project.path_with_namespace]
ui.info "Project URL: %s" % [project.project_url]
ui.info "Description: %s" % [project.description.nil? || project.description.empty? ? "N/A" : project.description]
ui.info "Default Branch: %s" % [project.default_branch.nil? ? "N/A" : project.default_branch]
ui.info "Owner: %s <%s>" % [project.owner.name, project.owner.email]
ui.info "Public?: %s" % [project.public.to_s]
ui.info "Issues enabled?: %s" % [project.issues_enabled.to_s]
ui.info "Merge Requests enabled?: %s" % [project.merge_requests_enabled.to_s]
ui.info "Wall enabled?: %s" % [project.wall_enabled.to_s]
ui.info "Wiki enabled?: %s" % [project.wiki_enabled.to_s]
ui.info "Created at: %s" % [Time.parse(project.created_at)]
end
end
end
end
end