glpl 0.0.0

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.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/bin/glpl +30 -0
  3. data/lib/glpl.rb +51 -0
  4. metadata +46 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a4c707dfcaa6c86a59609971e995966878debcbc
4
+ data.tar.gz: c4ff6ae93d0ad87ca5707bde56edf5baf366b0ce
5
+ SHA512:
6
+ metadata.gz: 8567d47ea862b2f381428db1999321f049c05eed5641e62e1a7f554011ddc6e25e43205749fefea906b71153ec59dd388b4f7922b5e37b97f4d8a34872235821
7
+ data.tar.gz: 41c8ea9cd024d49a53926e26ebd6447d0a5dd1e8ea6ffd62987b07a69a6cc72d271345643e8e1df108a05f9fa72c52befe68dac490f92b22de4426834667aa38
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'glpl'
4
+
5
+ private_token = `echo $GITLAB_PRIVATE_TOKEN`.strip()
6
+ if private_token == "" then
7
+ puts "Gitlab's Private Token is not defined. Export it to $GITLAB_PRIVATE_TOKEN."
8
+ exit
9
+ end
10
+
11
+ if ARGV.length == 0 then
12
+ puts "Project is not specified. Please specify the project using: $ glpl [PROJECT]."
13
+ exit
14
+ end
15
+
16
+ match = /#{ARGV[1]}:(?<id>[0-9]+)/.match(`echo $GLPL_PROJECT_IDS`)
17
+ if match == nil then
18
+ puts "Project ID is not defined for #{ARGV[1]}. Please update $GLPL_PROJECT_IDS."
19
+ exit
20
+ end
21
+ project_id = match.captures[0]
22
+
23
+ glpl = GLPL.new(private_token)
24
+ for pipeline in glpl.pipelines(project_id) do
25
+ printf("%s %s %s\n",
26
+ pipeline["id"].to_s.ljust(10),
27
+ pipeline["ref"].ljust(60),
28
+ pipeline["status"].ljust(10)
29
+ )
30
+ end
@@ -0,0 +1,51 @@
1
+ #!/Users/joaocosta/.rvm/rubies/ruby-2.2.1/bin/ruby
2
+
3
+ require 'json'
4
+ require 'net/http'
5
+
6
+ METHOD_CLASSES = {get: Net::HTTP::Get, post: Net::HTTP::Post}
7
+
8
+ # --- FUNCTIONS
9
+
10
+ class GLPL
11
+
12
+ ##
13
+ # Creates a new GLPL instance with the provided Gitlab's Private Token.
14
+ #
15
+ # Params:
16
+ # +private_token+:: +String+ Gitlab's Private Token to be used when making requests to Gitlab's API.
17
+ 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
+
25
+ end
26
+
27
+ # Prints the pipelines status for a given project.
28
+ # Params:
29
+ # +project_id+:: +String+ which contains the Gitlab's project id.
30
+ def pipelines(project_id)
31
+ pipelines = request("/#{project_id}/pipelines", :get)
32
+ end
33
+
34
+ # Makes an HTTP Requests to Gitlab's API and returns the response as JSON.
35
+ # Params:
36
+ # +endpoint+:: +String+ which represents the API's endpoint to be contacted.
37
+ # +method+:: +Symbol+ of the HTTP method, either :get or :post.
38
+ def request(endpoint, method)
39
+ uri = URI("#{@@api_url}#{endpoint}")
40
+
41
+ Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http|
42
+ request = METHOD_CLASSES[method].new(uri)
43
+ request["PRIVATE-TOKEN"] = @@private_token
44
+ response = http.request(request)
45
+
46
+ return JSON.parse(response.body)
47
+ end
48
+ end
49
+
50
+ private :request
51
+ end
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: glpl
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Dino
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-09-10 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Gitlab Pipelines on your command line.
14
+ email: dinojoaocosta@gmail.com
15
+ executables:
16
+ - glpl
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - bin/glpl
21
+ - lib/glpl.rb
22
+ homepage:
23
+ licenses:
24
+ - MIT
25
+ metadata: {}
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubyforge_project:
42
+ rubygems_version: 2.4.6
43
+ signing_key:
44
+ specification_version: 4
45
+ summary: Gitlab Pipelines on your command line.
46
+ test_files: []