ruboty-circle_ci_v2 0.1.0 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bb5c88f486abf15fb1f99e595f27c1a977b613f3ca2a4f20c9159baa72a2003f
4
- data.tar.gz: 19d47b2d3fe28396de69376aecb3c4277428ba971da1ba73b86d6ff0c252b3f5
3
+ metadata.gz: b854db3327ddfbe3bd7c0b22811646342596f9da8de867b8e9bdce61720a48d3
4
+ data.tar.gz: c37e39fea9e9bde5068a0e963615b62a667cd14e426a177a83fa527b7a3fb76c
5
5
  SHA512:
6
- metadata.gz: 0b6630f26a998de44aad92fca91f89406040f019a61a392de282949db8649b12e49f3abfe294708ccba29647cfe41f30e5a87ad62fdad50e70f0c1ad744f015d
7
- data.tar.gz: 2824f3a06bdd11d06dc2a44f2767ca185d4f3f4d4952b18a466017721dc91674484c45d39de90958e106812f45141a953216f9791cc5ceb4e3788ebd27485e56
6
+ metadata.gz: 79ebea2ee3f89dbace5e7b9ea3be3c7ca86af64ead425c10615d8d3e2148d3ab9b89ddceacf92f81be70ba4757b559a50f9e5bd7cc59d26b467df56941cfce86
7
+ data.tar.gz: 1c7e708b93f1d03549c101cf433351f3b4ded29e6cd22f74ca92188757c005c60a795b40aa11c5b1b96ad5789441d3d2c8225584b2aa91bfed2890a5e2b8baca
@@ -16,16 +16,12 @@ module Ruboty
16
16
  message.robot.brain.data[NAMESPACE] ||= {}
17
17
  end
18
18
 
19
- def body
20
- message[:description] || ""
21
- end
22
-
23
19
  def sender_name
24
20
  message.from_name
25
21
  end
26
22
 
27
23
  def require_personal_api_token
28
- message.reply("I don't know your CircleCI Personal API Token")
24
+ message.reply("I don't know your CircleCI personal api token")
29
25
  end
30
26
 
31
27
  def has_personal_api_token?
@@ -37,7 +33,7 @@ module Ruboty
37
33
  end
38
34
 
39
35
  def connection
40
- Faraday.new(url: api_endpoint) do |builder|
36
+ Faraday.new(url: circle_ci_v2_base_url) do |builder|
41
37
  builder.request :url_encoded
42
38
  builder.adapter :net_http
43
39
  builder.basic_auth personal_api_token, ""
@@ -45,16 +41,8 @@ module Ruboty
45
41
  end
46
42
  end
47
43
 
48
- def repository
49
- message[:repo]
50
- end
51
-
52
- def api_endpoint
53
- "#{circle_ci_v2_base_url}/#{repository}/pipeline"
54
- end
55
-
56
44
  def circle_ci_v2_base_url
57
- "https://circleci.com/api/v2/project"
45
+ "https://circleci.com/api/v2"
58
46
  end
59
47
  end
60
48
  end
@@ -10,7 +10,7 @@ module Ruboty
10
10
  private
11
11
 
12
12
  def report
13
- message.reply("Remembered #{sender_name}'s CircleCI personal access token")
13
+ message.reply("Remembered #{sender_name}'s CircleCI personal api token")
14
14
  end
15
15
 
16
16
  def remember
@@ -13,21 +13,35 @@ module Ruboty
13
13
  private
14
14
 
15
15
  def run_pipeline
16
- connection.post do |request|
16
+ pipeline_response = connection.post("project/#{project_slug}/pipeline") do |request|
17
17
  request.body = {
18
18
  branch: branch,
19
19
  parameters: parameters
20
20
  }.to_json
21
21
  end
22
- end
22
+ pipeline = JSON.parse(pipeline_response.body)
23
23
 
24
- def branch
25
- message[:branch]
24
+ workflow_response = connection.get("pipeline/#{pipeline["id"]}/workflow")
25
+ workflow = JSON.parse(workflow_response.body)
26
+ workflow_item_id = workflow["items"].first["id"]
27
+ workflow_item_url = "https://app.circleci.com/pipelines/#{project_slug}/#{pipeline["number"]}/workflows/#{workflow_item_id}"
28
+
29
+ message.reply("Triggered #{workflow_item_url}")
30
+ rescue => e
31
+ message.reply("An error has occurred: #{e.message}")
26
32
  end
27
33
 
28
34
  def parameters
29
35
  JSON.parse(message[:params])
30
36
  end
37
+
38
+ def project_slug
39
+ message[:project_slug]
40
+ end
41
+
42
+ def branch
43
+ message[:branch]
44
+ end
31
45
  end
32
46
  end
33
47
  end
@@ -1,5 +1,5 @@
1
1
  module Ruboty
2
2
  module CircleCIV2
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -2,13 +2,13 @@ module Ruboty
2
2
  module Handlers
3
3
  class CircleCIV2 < Base
4
4
  on(
5
- /remember my ciecleci personal api token (?<token>.+)\z/,
5
+ /remember my circleci personal api token (?<token>.+)\z/,
6
6
  name: "remember",
7
7
  description: "Remember sender's CircleCI personal api token",
8
8
  )
9
9
 
10
10
  on(
11
- /run circleci pipeline of branch (?<branch>.+) on (?<repo>.+) with params (?<params>.+)\z/,
11
+ /run circleci pipeline of branch (?<branch>.+) on (?<project_slug>.+) with params (?<params>.+)\z/,
12
12
  name: "run_pipeline",
13
13
  description: "Run pipeline with params",
14
14
  )
@@ -22,4 +22,4 @@ module Ruboty
22
22
  end
23
23
  end
24
24
  end
25
- end
25
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruboty-circle_ci_v2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kouhei Suzuki
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-06 00:00:00.000000000 Z
11
+ date: 2020-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruboty