glpl 0.0.0 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a4c707dfcaa6c86a59609971e995966878debcbc
4
- data.tar.gz: c4ff6ae93d0ad87ca5707bde56edf5baf366b0ce
3
+ metadata.gz: 6a8aaf48584aeb649d2059f431309140ba1617f5
4
+ data.tar.gz: 3706f52730c4fba61ff26f21f84922c4f86753af
5
5
  SHA512:
6
- metadata.gz: 8567d47ea862b2f381428db1999321f049c05eed5641e62e1a7f554011ddc6e25e43205749fefea906b71153ec59dd388b4f7922b5e37b97f4d8a34872235821
7
- data.tar.gz: 41c8ea9cd024d49a53926e26ebd6447d0a5dd1e8ea6ffd62987b07a69a6cc72d271345643e8e1df108a05f9fa72c52befe68dac490f92b22de4426834667aa38
6
+ metadata.gz: f45ae4f75b50bbbed32c26a69306233d35d6c04f92b17901f547f5109fb75a0e3d8d06a801c2c30c86d072e6a9638f68491542f6d74a28022efee18784537235
7
+ data.tar.gz: 73b8f64e96f4484583e507300e00f63ad632e50f0059981d3f7e44f28b839fddaa2f3652d5f9e2b01c6f52891f8ba214a30525da5d0edb486f17c9a8ab72410d
data/bin/glpl CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ require 'optparse'
3
4
  require 'glpl'
4
5
 
5
6
  private_token = `echo $GITLAB_PRIVATE_TOKEN`.strip()
@@ -13,18 +14,39 @@ if ARGV.length == 0 then
13
14
  exit
14
15
  end
15
16
 
16
- match = /#{ARGV[1]}:(?<id>[0-9]+)/.match(`echo $GLPL_PROJECT_IDS`)
17
+ match = /#{ARGV[0]}:(?<id>[0-9]+)/.match(`echo $GLPL_PROJECT_IDS`)
17
18
  if match == nil then
18
- puts "Project ID is not defined for #{ARGV[1]}. Please update $GLPL_PROJECT_IDS."
19
+ puts "Project ID is not defined for #{ARGV[0]}. Please update $GLPL_PROJECT_IDS."
19
20
  exit
20
21
  end
21
22
  project_id = match.captures[0]
22
23
 
24
+ options = {}
25
+ OptionParser.new do |opts|
26
+ opts.banner = "Usage: glpl [PROJECT_NAME] [options]"
27
+
28
+ opts.on("-p", "--pipeline ID", Integer, "Pipeline ID") do |pipeline_id|
29
+ options[:pipeline_id] = pipeline_id
30
+ end
31
+ end.parse!
32
+
23
33
  glpl = GLPL.new(private_token)
34
+
35
+ if options.key?(:pipeline_id) then
36
+ for job in glpl.jobs(project_id, options[:pipeline_id]) do
37
+ printf("%s %s %s\n",
38
+ job.id.to_s.ljust(10),
39
+ job.name.ljust(60),
40
+ job.status.ljust(10)
41
+ )
42
+ end
43
+ exit
44
+ end
45
+
24
46
  for pipeline in glpl.pipelines(project_id) do
25
47
  printf("%s %s %s\n",
26
- pipeline["id"].to_s.ljust(10),
27
- pipeline["ref"].ljust(60),
28
- pipeline["status"].ljust(10)
48
+ pipeline.id.to_s.ljust(10),
49
+ pipeline.ref.ljust(60),
50
+ pipeline.status.ljust(10)
29
51
  )
30
52
  end
@@ -1,5 +1,3 @@
1
- #!/Users/joaocosta/.rvm/rubies/ruby-2.2.1/bin/ruby
2
-
3
1
  require 'json'
4
2
  require 'net/http'
5
3
 
@@ -8,27 +6,28 @@ METHOD_CLASSES = {get: Net::HTTP::Get, post: Net::HTTP::Post}
8
6
  # --- FUNCTIONS
9
7
 
10
8
  class GLPL
11
-
12
9
  ##
13
10
  # Creates a new GLPL instance with the provided Gitlab's Private Token.
14
11
  #
15
12
  # Params:
16
13
  # +private_token+:: +String+ Gitlab's Private Token to be used when making requests to Gitlab's API.
17
14
  def initialize(private_token)
18
- @@private_token = `echo $GITLAB_PRIVATE_TOKEN`.strip()
19
- @@api_url = "https://gitlab.com/api/v4/projects"
20
-
21
- if @@private_token == "" then
22
- raise ArgumentError.new("Gitlab Private's Token is not set. Export it to $GITLAB_PRIVATE_TOKEN.")
23
- end
24
-
15
+ @private_token = private_token
16
+ @api_url = "https://gitlab.com/api/v4/projects"
25
17
  end
26
-
27
- # Prints the pipelines status for a given project.
18
+ # List recent pipelines for a given project.
28
19
  # Params:
29
- # +project_id+:: +String+ which contains the Gitlab's project id.
20
+ # +project_id+:: +Integer+ which contains the Gitlab's project id.
30
21
  def pipelines(project_id)
31
- pipelines = request("/#{project_id}/pipelines", :get)
22
+ request("/#{project_id}/pipelines", :get).map { |data| GLPL::Pipeline.new(data) }
23
+ end
24
+
25
+ # List jobs for a given project's pipeline.
26
+ # Params:
27
+ # +project_id+:: +Integer+ Gitlab's project ID.
28
+ # +pipeline_id+:: +Integer+ The pipeline's ID.
29
+ def jobs(project_id, pipeline_id)
30
+ request("/#{project_id}/pipelines/#{pipeline_id}/jobs", :get).map { |data| GLPL::Job.new(data) }
32
31
  end
33
32
 
34
33
  # Makes an HTTP Requests to Gitlab's API and returns the response as JSON.
@@ -36,11 +35,11 @@ class GLPL
36
35
  # +endpoint+:: +String+ which represents the API's endpoint to be contacted.
37
36
  # +method+:: +Symbol+ of the HTTP method, either :get or :post.
38
37
  def request(endpoint, method)
39
- uri = URI("#{@@api_url}#{endpoint}")
38
+ uri = URI("#{@api_url}#{endpoint}")
40
39
 
41
40
  Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http|
42
41
  request = METHOD_CLASSES[method].new(uri)
43
- request["PRIVATE-TOKEN"] = @@private_token
42
+ request["PRIVATE-TOKEN"] = @private_token
44
43
  response = http.request(request)
45
44
 
46
45
  return JSON.parse(response.body)
@@ -49,3 +48,6 @@ class GLPL
49
48
 
50
49
  private :request
51
50
  end
51
+
52
+ require 'glpl/pipeline'
53
+ require 'glpl/job'
@@ -0,0 +1,15 @@
1
+ class GLPL::Job
2
+
3
+ attr_reader :id, :status, :stage, :name, :ref, :created_at, :username
4
+
5
+ def initialize(job_data)
6
+ @id = job_data["id"]
7
+ @status = job_data["status"]
8
+ @stage = job_data["stage"]
9
+ @name = job_data["name"]
10
+ @ref = job_data["ref"]
11
+ @created_at = job_data["created_at"]
12
+ @username = job_data["username"]
13
+ end
14
+
15
+ end
@@ -0,0 +1,12 @@
1
+ class GLPL::Pipeline
2
+
3
+ attr_reader :id, :sha, :ref, :status, :url
4
+
5
+ def initialize(pipeline_data)
6
+ @id = pipeline_data["id"]
7
+ @sha = pipeline_data["sha"]
8
+ @ref = pipeline_data["ref"]
9
+ @status = pipeline_data["status"]
10
+ @url = pipeline_data["web_url"]
11
+ end
12
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glpl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dino
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-10 00:00:00.000000000 Z
11
+ date: 2018-09-22 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Gitlab Pipelines on your command line.
14
14
  email: dinojoaocosta@gmail.com
@@ -19,10 +19,13 @@ extra_rdoc_files: []
19
19
  files:
20
20
  - bin/glpl
21
21
  - lib/glpl.rb
22
- homepage:
22
+ - lib/glpl/job.rb
23
+ - lib/glpl/pipeline.rb
24
+ homepage: https://github.com/joaofcosta/glpl
23
25
  licenses:
24
26
  - MIT
25
- metadata: {}
27
+ metadata:
28
+ source_code_url: https://github.com/joaofcosta/glpl
26
29
  post_install_message:
27
30
  rdoc_options: []
28
31
  require_paths: