st 0.0.2 → 0.0.4

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 (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/st.rb +37 -11
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c06012377c62972bf2270cb3df1cf116ef69f7ce340c05c01ea38633c5d78034
4
- data.tar.gz: 4c7ab5cb7a48ddd0fabd113aed756bc1c157f9a56d90e78f1dbd8956bce14c0a
3
+ metadata.gz: c420486b3131824514f83efa7b3f8bbfc6613a74113f029b99566c19e1db9784
4
+ data.tar.gz: df07f0aff1bdc38342ff09f08297459645359e0545a33b60ece77015ff9631c1
5
5
  SHA512:
6
- metadata.gz: 42fb0ddd2ee50272af5b07cf49a202ac2163a82baf9779efa490c21b670b0c129861310900fa21b2188b1d928ddca7706791cd2ecdf230e6be437be2e3fbf452
7
- data.tar.gz: 7423143506449ede6470df4b63983f69e86551c2a683cf1204a088661ff1f65114f6055f383feed82d0803ff8bdee693be512ea8ec6de4910e1958270647323e
6
+ metadata.gz: a616f5df60b8f9b81012d9058072c1c8d704811ed150e5e55a3ffdbbc6c36b49da898072bda7b9083d6117c28d9b47a800da745562a26fbb1be4bfd37637a6a1
7
+ data.tar.gz: 2641165617137398793da72ba9927cc7c21e84ae550bc714b893f0402b03d8de0505e3c7525c213454b7d6abd491d1d92769542d4fd584eccfe4fc3709bec6de
data/lib/st.rb CHANGED
@@ -4,8 +4,12 @@ require 'aws-sdk-codedeploy'
4
4
 
5
5
  $stdout.sync = true
6
6
 
7
+ # Usage: st [-sha] [branch]
7
8
  def main
8
- ppls = get_ppls
9
+ shaflag = !!ARGV.delete('-sha')
10
+ branch = ARGV[0] || 'master'
11
+
12
+ ppls = get_ppls(branch)
9
13
  ppls = ppls.select { |ppl| ppl['name'] == 'Backend application' }
10
14
  ppls = ppls.uniq { |ppl| ppl['commit_sha'] }
11
15
 
@@ -15,23 +19,34 @@ def main
15
19
  sha = ppl['commit_sha']
16
20
  state = ppl['state']
17
21
  result = ppl['result'] || 'None'
18
- deployment_info = deployments_info.find { |di| di.revision.git_hub_location.commit_id == ppl['commit_sha'] }
19
- deployment_status = deployment_info ? deployment_info.status : 'None'
20
- begin
21
- printf("%s\t%s\t%-16s%s\n", state, result, deployment_status, sha)
22
- rescue Errno::EPIPE
23
- break
22
+ status = deployment_status(deployments_info, sha)
23
+
24
+ if shaflag
25
+ msg = sha
26
+ printf("%s\t%s\t%-16s%s\n", state, result, status, msg)
27
+ else
28
+ commit = get_commit(sha)
29
+ msg = commit['message'].split("\n")[0]
30
+ author = commit['author']['name'].split[0]
31
+ printf("%s\t%s\t%-16s%s\t%s\n", state, result, status, author, msg)
24
32
  end
33
+
34
+ rescue Errno::EPIPE
35
+ break
25
36
  end
26
37
  end
27
38
 
28
- def get_ppls
39
+ def deployment_status(deployments_info, sha)
40
+ deployment_info = deployments_info.find { |di| di.revision.git_hub_location.commit_id == sha }
41
+ deployment_status = deployment_info ? deployment_info.status : 'None'
42
+ end
43
+
44
+ def get_ppls(branch)
29
45
  root = 'https://studytube.semaphoreci.com/api/v1alpha'
30
46
  project_id = '42370de0-9568-4c26-87ad-559b2294c3c1'
31
- branch = 'master'
32
47
  url = "#{root}/pipelines?project_id=#{project_id}&branch_name=#{branch}"
33
- filepath = "#{ENV['HOME']}/.studytube/credentials/semaphoreci"
34
- token = File.open(filepath) { |f| f.readline }.chomp
48
+ filepath = "#{ENV['HOME']}/.studytube/semaphorecitoken"
49
+ token = File.read(filepath).chomp
35
50
  str = URI.open(url, 'Authorization' => "Token #{token}").read
36
51
  JSON.parse(str)
37
52
  end
@@ -46,3 +61,14 @@ def get_deployments_info
46
61
 
47
62
  aws.batch_get_deployments(deployment_ids: res.deployments).deployments_info
48
63
  end
64
+
65
+ def get_commit(sha)
66
+ repo='backend'
67
+ owner='Studytube'
68
+ filepath = "#{ENV['HOME']}/.studytube/githubtoken"
69
+ token = File.read(filepath).chomp
70
+
71
+ url = "https://api.github.com/repos/#{owner}/#{repo}/git/commits/#{sha}"
72
+ str = URI.open(url, 'Authorization' => "Token #{token}").read
73
+ JSON.parse(str)
74
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: st
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kostya Dubinin