git-semaphore 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 796fce310598b663f7a73fa5f98d68602de41bf6
4
- data.tar.gz: 25ace2adb5a1a3f245ab1a02c9f86553917d0550
3
+ metadata.gz: 40184be592c2c2afc8dc9ca98da908756e67df2d
4
+ data.tar.gz: ee4104f83902c4e3ccbfde0514f4e00d84e36ccd
5
5
  SHA512:
6
- metadata.gz: 24e942d6b710d328183c42d89937ca5e80c2c51ed5dc2d3e5f5cea4780bd3b1b2ad890c3bfb43d01a55dbcbcb2b7b4bba889e1adb7473562662d4ad00bc488b0
7
- data.tar.gz: 168659a4950ecdba848365456bea3052ca393734cf72e942affdf81e859fbdfb139067a303e21b5ee44124f1143030b450e69df4a338f0996ce54739ede739f4
6
+ metadata.gz: 86e2abea939c3ad674cffdd68f01bb8d39651d281b9d51a1ef4bc9a325c5b2cea8ea5c22a4b9ed1e8e2ff782b873037921b2dc70844782422631ce69b8844fe1
7
+ data.tar.gz: 041c9f620e57de36d55849665c3ff06f153870bdbe8c3a508c03dcb471705a70abe192e950064e683370ad6ebb97a585c6a9797933101fcde3de197d6a40e154
data/README.md CHANGED
@@ -38,17 +38,17 @@ The following [Semaphore API][] features are supported by `git semaphore`:
38
38
 
39
39
  | API feature | | command |summary |
40
40
  |------------------|----|---------|--------|
41
- | [authentication][] | ✅ | | provide user authentication via an authentication token |
42
- | [projects][] | ✅ | `git semaphore --projects` | list all projects and their current status |
43
- | [project branches][] | ✅ | `git semaphore --branches` | list all branches for the current project |
44
- | [branch status][] | ✅ | `git semaphore --status` | list the build status for the current branch |
45
- | [branch history][] | ✅ | `git semaphore --history` | list the build history for the current branch |
46
- | [build information][] | | | detailed information for a given build number |
47
- | [build log][] | ❌ | | execution logs for a given build number _(per thread and command)_ |
48
- | [rebuild][] | ✅ | `git semaphore --rebuild` | rebuild last revision for the current branch |
49
- | [launch build][] | ❌ | | launch a build for the given commit SHA |
50
- | [stop][] | ❌ | | stop an in-progress build |
51
- | [deploy][] | ❌ | | run a deploy from a given build |
41
+ | [authentication][] | ✅ | | provide user authentication via an authentication token |
42
+ | [projects][] | ✅ | `git semaphore --projects` | list all projects and their current status |
43
+ | [project branches][] | ✅ | `git semaphore --branches` | list all branches for the current project |
44
+ | [branch status][] | ✅ | `git semaphore --status` | list the build status for the current branch |
45
+ | [branch history][] | ✅ | `git semaphore --history` | list the build history for the current branch |
46
+ | [build information][] | | `git semaphore --information` | detailed information for a given build number _(ie. all commits)_ |
47
+ | [build log][] | ❌ | | execution logs for a given build number _(per thread and command)_ |
48
+ | [rebuild][] | ✅ | `git semaphore --rebuild` | rebuild last revision for the current branch |
49
+ | [launch build][] | ❌ | | launch a build for the given commit SHA |
50
+ | [stop][] | ❌ | | stop an in-progress build |
51
+ | [deploy][] | ❌ | | run a deploy from a given build |
52
52
 
53
53
  [project branches]: https://semaphoreci.com/docs/branches-and-builds-api.html#project_branches
54
54
  [branch status]: https://semaphoreci.com/docs/branches-and-builds-api.html#branch_status
@@ -111,6 +111,7 @@ When used inside a git repository, `git semaphore` uses [convention over configu
111
111
  | project name | derived from pwd | `File.basename(Dir.pwd)` | `ENV['SEMAPHORE_PROJECT_NAME']` |
112
112
  | branch name | current git branch | `git symbolic-ref --short HEAD` | `ENV['SEMAPHORE_BRANCH_NAME']` |
113
113
  | commit SHA | current git head | `git rev-parse HEAD` | `ENV['SEMAPHORE_COMMIT_SHA']` |
114
+ | build number | last branch build | `N/A` | `ENV['SEMAPHORE_BUILD_NUMBER']` |
114
115
 
115
116
  However, each of these defaults can be overridden by setting the corresponding environment variable, as documented in the above table. The same `ENV`-based override mechanism can be leveraged to use `git semaphore` outside of a git repository.
116
117
 
@@ -171,6 +172,12 @@ _(the project and branch names are derived from the current git repository and t
171
172
 
172
173
  _(the project and branch names are derived from the current git repository and the current git head)_
173
174
 
175
+ ### commit information for the last build of a project's branch
176
+
177
+ git semaphore --information
178
+
179
+ _(the project and branch names are derived from the current git repository and the current git head)_
180
+
174
181
  ## Formatting the raw `git semaphore` JSON output
175
182
 
176
183
  After installing [the indispensable jq utility][jq] (`brew install jq`), the raw JSON output generated by the various `git semaphore` commands can be formatted and queried as follows:
@@ -186,6 +193,9 @@ After installing [the indispensable jq utility][jq] (`brew install jq`), the raw
186
193
 
187
194
  # list the build duration (in minutes) for all "passed" builds of the current branch
188
195
  git semaphore --history | jq -r '.builds | .[] | select(.result == "passed") | (.build_number|tostring) + "\t" + (.duration.minutes|tostring)'
196
+
197
+ # list all commit SHAs that triggered the latest build
198
+ git semaphore --information | jq -r '.commits | .[] | .id'
189
199
 
190
200
  [semaphoreci.com]: https://semaphoreci.com/
191
201
  [account settings]: https://semaphoreci.com/users/edit
data/exe/git-semaphore CHANGED
@@ -22,11 +22,12 @@ if __FILE__ == $0
22
22
 
23
23
  on :clean, 'Deletes the cached API query results'
24
24
 
25
- on :projects, 'List all projects and their current status'
26
- on :branches, 'List all branches for the current project'
27
- on :status, 'List the build status for the current branch'
28
- on :history, 'List the build history for the current branch'
29
- on :rebuild, 'Rebuild last revision for the current branch'
25
+ on :projects, 'List all projects and their current status'
26
+ on :branches, 'List all branches for the current project'
27
+ on :status, 'List the build status for the current branch'
28
+ on :history, 'List the build history for the current branch'
29
+ on :information, 'List the commit information for the last build'
30
+ on :rebuild, 'Rebuild last revision for the current branch'
30
31
 
31
32
  end
32
33
 
@@ -67,6 +68,11 @@ if __FILE__ == $0
67
68
  exit 0
68
69
  end
69
70
 
71
+ if options.information?
72
+ puts app.information.to_json
73
+ exit 0
74
+ end
75
+
70
76
  if options.rebuild?
71
77
  puts app.rebuild
72
78
  exit 0
@@ -20,6 +20,10 @@ module Git
20
20
  end
21
21
  end
22
22
 
23
+ def self.information project_hash_id, branch_id, build_number, auth_token
24
+ get_json information_uri(project_hash_id, branch_id, build_number, auth_token)
25
+ end
26
+
23
27
  def self.rebuild project_hash_id, branch_id, auth_token
24
28
  get_json last_revision_uri(project_hash_id, branch_id, auth_token), :post
25
29
  end
@@ -58,6 +62,14 @@ module Git
58
62
 
59
63
  private_class_method :history_uri
60
64
 
65
+ def self.information_uri project_hash_id, branch_id, build_number, auth_token
66
+ # https://semaphoreci.com/docs/branches-and-builds-api.html#build_information
67
+ # GET /api/v1/projects/:hash_id/:id/builds/:number
68
+ request_uri(auth_token, :path => File.join('projects', project_hash_id, branch_id, 'builds', build_number))
69
+ end
70
+
71
+ private_class_method :information_uri
72
+
61
73
  def self.last_revision_uri project_hash_id, branch_id, auth_token
62
74
  # https://semaphoreci.com/docs/branches-and-builds-api.html#rebuild
63
75
  # POST /api/v1/projects/:project_hash_id/:branch_id/build
@@ -27,6 +27,12 @@ module Git
27
27
  end
28
28
  end
29
29
 
30
+ def self.information project_hash_id, branch_id, build_number, auth_token
31
+ @information ||= Git::Semaphore.from_json_cache(information_cache(project_hash_id, branch_id, build_number)) do
32
+ API.information project_hash_id, branch_id, build_number, auth_token
33
+ end
34
+ end
35
+
30
36
  # private helper functions
31
37
 
32
38
  def self.projects_cache
@@ -53,6 +59,12 @@ module Git
53
59
 
54
60
  private_class_method :history_cache
55
61
 
62
+ def self.information_cache project_hash_id, branch_id, build_number
63
+ File.join(Git::Semaphore.cache_dir_for(project_hash_id), "#{branch_id}_#{build_number}_information.json")
64
+ end
65
+
66
+ private_class_method :information_cache
67
+
56
68
  end
57
69
  end
58
70
  end
@@ -3,6 +3,7 @@ class Git::Semaphore::App
3
3
  attr_writer :project_name
4
4
  attr_writer :branch_name
5
5
  attr_writer :commit_sha
6
+ attr_writer :build_number
6
7
 
7
8
  attr_reader :branch_url
8
9
 
@@ -13,6 +14,7 @@ class Git::Semaphore::App
13
14
  self.project_name = config['SEMAPHORE_PROJECT_NAME']
14
15
  self.branch_name = config['SEMAPHORE_BRANCH_NAME']
15
16
  self.commit_sha = config['SEMAPHORE_COMMIT_SHA']
17
+ self.build_number = config['SEMAPHORE_BUILD_NUMBER']
16
18
  end
17
19
 
18
20
  def to_json
@@ -21,6 +23,7 @@ class Git::Semaphore::App
21
23
  semaphore_project_name: self.project_name,
22
24
  semaphore_branch_name: self.branch_name,
23
25
  semaphore_commit_sha: self.commit_sha,
26
+ semaphore_build_number: self.build_number,
24
27
  }.to_json
25
28
  end
26
29
 
@@ -39,6 +42,11 @@ class Git::Semaphore::App
39
42
  @git_repo.head.commit.id if @git_repo
40
43
  end
41
44
 
45
+ def build_number
46
+ return @build_number unless @build_number.nil?
47
+ history['builds'].first['build_number'].to_s
48
+ end
49
+
42
50
  def projects
43
51
  Git::Semaphore::API::Cache.projects(@auth_token)
44
52
  end
@@ -55,6 +63,10 @@ class Git::Semaphore::App
55
63
  Git::Semaphore::API::Cache.history(project_hash_id, branch_id, @auth_token)
56
64
  end
57
65
 
66
+ def information
67
+ Git::Semaphore::API::Cache.information(project_hash_id, branch_id, build_number, @auth_token,)
68
+ end
69
+
58
70
  def rebuild
59
71
  Git::Semaphore::API.rebuild(project_hash_id, branch_id, @auth_token)
60
72
  end
@@ -104,12 +116,8 @@ class Git::Semaphore::App
104
116
  branch_id_for(branch_name)
105
117
  end
106
118
 
107
- def build_statuses
108
- history['builds']
109
- end
110
-
111
119
  def build_status_for commit_sha
112
- build_statuses.find { |build_status|
120
+ history['builds'].find { |build_status|
113
121
  build_status['commit']['id'] == commit_sha
114
122
  }
115
123
  end
@@ -1,5 +1,5 @@
1
1
  module Git
2
2
  module Semaphore
3
- VERSION = "1.0.0"
3
+ VERSION = "1.1.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-semaphore
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Vandenberk
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-06-27 00:00:00.000000000 Z
11
+ date: 2016-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: slop