ruboty-github_actions 0.1.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 +7 -0
- data/README.md +69 -0
- data/lib/ruboty/github_actions/actions/client.rb +23 -0
- data/lib/ruboty/github_actions/actions/run_workflow.rb +35 -0
- data/lib/ruboty/github_actions/actions/set_credential.rb +17 -0
- data/lib/ruboty/github_actions/credential.rb +31 -0
- data/lib/ruboty/github_actions/handlers/github_actions.rb +29 -0
- data/lib/ruboty/github_actions/version.rb +7 -0
- data/lib/ruboty/github_actions.rb +16 -0
- data/lib/ruboty-github_actions.rb +3 -0
- metadata +89 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 0b7f1d6a639921e72c8f477d9030a78a4742a8c5d8cb798dd163fad49abdd75e
|
|
4
|
+
data.tar.gz: 006ec7480c7ee6e6ef561b4a4120e9b006def396b72b158b6bbfbd9fc0f249ab
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: da1944e77c53e3e130459e583e9e875ba0c7397fb9c414d398058301a93ba8eed77a692dd558686e786ebe5f029f22e19ed49456ee028e008fce464c352df5b9
|
|
7
|
+
data.tar.gz: 8dc6f22faa338433a6dac1075b8eef66ccfa4c55fcf879692b9c821602592543ade84940636d22dee30a213d85666256667f86559c20fbf7f32532c7f270971a
|
data/README.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# ruboty-github_actions
|
|
2
|
+
|
|
3
|
+
A ruboty plugin to trigger GitHub Actions workflows via chat.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your ruboty project's Gemfile:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem "ruboty-github_actions"
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
And then execute:
|
|
14
|
+
|
|
15
|
+
```console
|
|
16
|
+
$ bundle
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
### Set a credential
|
|
22
|
+
|
|
23
|
+
Register a GitHub Personal Access Token for a user:
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
ruboty github actions set credential <user> <token>
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Example:
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
ruboty github actions set credential alice ghp_xxxxxxxxxxxx
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
The credential is stored in the ruboty brain.
|
|
36
|
+
|
|
37
|
+
### Fallback credential
|
|
38
|
+
|
|
39
|
+
If the user has no credential saved by this plugin, the GitHub access token saved by [ruboty-qiita-github](https://github.com/increments/ruboty-qiita-github) (stored under the `github` key in the brain) is used as a fallback. A credential saved via `set credential` always takes precedence.
|
|
40
|
+
|
|
41
|
+
### Dispatch a workflow
|
|
42
|
+
|
|
43
|
+
Trigger a workflow run:
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
ruboty github actions run <repo> <workflow> <branch> [key=value,key2=value2 ...]
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Example:
|
|
50
|
+
|
|
51
|
+
```
|
|
52
|
+
ruboty github actions run tomoasleep/myapp deploy main env=production
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
The workflow runs as the user who sent the message.
|
|
56
|
+
|
|
57
|
+
## Configuration
|
|
58
|
+
|
|
59
|
+
| Environment variable | Description |
|
|
60
|
+
|----------------------|-------------|
|
|
61
|
+
| `RUBOTY_GITHUB_ACTIONS_API_URL` | GitHub API base URL (optional, for testing/local emulation) |
|
|
62
|
+
|
|
63
|
+
## Development
|
|
64
|
+
|
|
65
|
+
Run the test suite:
|
|
66
|
+
|
|
67
|
+
```console
|
|
68
|
+
$ bundle exec rspec
|
|
69
|
+
```
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Ruboty
|
|
4
|
+
module GithubActions
|
|
5
|
+
module Actions
|
|
6
|
+
class Client
|
|
7
|
+
class << self
|
|
8
|
+
def build(credential)
|
|
9
|
+
Octokit::Client.new(access_token: credential[:token], **base_options)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
private
|
|
13
|
+
|
|
14
|
+
def base_options
|
|
15
|
+
options = {}
|
|
16
|
+
options[:api_endpoint] = ENV["RUBOTY_GITHUB_ACTIONS_API_URL"] if ENV["RUBOTY_GITHUB_ACTIONS_API_URL"]
|
|
17
|
+
options
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Ruboty
|
|
4
|
+
module GithubActions
|
|
5
|
+
module Actions
|
|
6
|
+
class RunWorkflow < Ruboty::Actions::Base
|
|
7
|
+
def call
|
|
8
|
+
repo = message[1]
|
|
9
|
+
workflow = message[2]
|
|
10
|
+
ref = message[3]
|
|
11
|
+
inputs = parse_inputs(message[4])
|
|
12
|
+
|
|
13
|
+
credential = Credential.find(message.robot.brain, message.from_name)
|
|
14
|
+
return message.reply("No credential found for #{message.from_name}") unless credential
|
|
15
|
+
|
|
16
|
+
client = Client.build(credential)
|
|
17
|
+
return message.reply("Workflow #{workflow} dispatch failed for #{repo}") unless client.workflow_dispatch(repo, workflow, ref, inputs: inputs)
|
|
18
|
+
|
|
19
|
+
message.reply("Workflow #{workflow} dispatched for #{repo}")
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
def parse_inputs(raw)
|
|
25
|
+
return {} unless raw
|
|
26
|
+
|
|
27
|
+
raw.split(",").each_with_object({}) do |pair, hash|
|
|
28
|
+
key, value = pair.split("=", 2)
|
|
29
|
+
hash[key.to_sym] = value
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Ruboty
|
|
4
|
+
module GithubActions
|
|
5
|
+
module Actions
|
|
6
|
+
class SetCredential < Ruboty::Actions::Base
|
|
7
|
+
def call
|
|
8
|
+
user = message[1]
|
|
9
|
+
token = message[2]
|
|
10
|
+
|
|
11
|
+
Credential.save(message.robot.brain, user, type: "pat", token: token)
|
|
12
|
+
message.reply("Credential saved for #{user}")
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Ruboty
|
|
4
|
+
module GithubActions
|
|
5
|
+
class Credential
|
|
6
|
+
PREFIX = "github_actions:credentials"
|
|
7
|
+
QIITA_GITHUB_NAMESPACE = "github"
|
|
8
|
+
|
|
9
|
+
class << self
|
|
10
|
+
def save(brain, user, attributes)
|
|
11
|
+
brain.data[key_for(user)] = attributes
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def find(brain, user)
|
|
15
|
+
brain.data[key_for(user)] || from_qiita_github(brain, user)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
private
|
|
19
|
+
|
|
20
|
+
def key_for(user)
|
|
21
|
+
"#{PREFIX}:#{user}"
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def from_qiita_github(brain, user)
|
|
25
|
+
token = brain.data[QIITA_GITHUB_NAMESPACE].to_h[user]
|
|
26
|
+
{ type: "pat", token: token } if token
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Ruboty
|
|
4
|
+
module GithubActions
|
|
5
|
+
module Handlers
|
|
6
|
+
class GithubActions < Ruboty::Handlers::Base
|
|
7
|
+
on(
|
|
8
|
+
/github actions set credential (?<user>\S+) (?<token>\S+)\z/,
|
|
9
|
+
name: "set_credential",
|
|
10
|
+
description: "Set a GitHub PAT credential for a user"
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
on(
|
|
14
|
+
/github actions run (?<repo>\S+) (?<workflow>\S+) (?<ref>\S+)(?<inputs> [\S,=]+)?\z/,
|
|
15
|
+
name: "run",
|
|
16
|
+
description: "Dispatch a GitHub Actions workflow"
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
def set_credential(message)
|
|
20
|
+
Ruboty::GithubActions::Actions::SetCredential.new(message).call
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def run(message)
|
|
24
|
+
Ruboty::GithubActions::Actions::RunWorkflow.new(message).call
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "ruboty"
|
|
4
|
+
require "octokit"
|
|
5
|
+
|
|
6
|
+
require "ruboty/github_actions/version"
|
|
7
|
+
require "ruboty/github_actions/credential"
|
|
8
|
+
require "ruboty/github_actions/actions/client"
|
|
9
|
+
require "ruboty/github_actions/actions/set_credential"
|
|
10
|
+
require "ruboty/github_actions/actions/run_workflow"
|
|
11
|
+
require "ruboty/github_actions/handlers/github_actions"
|
|
12
|
+
|
|
13
|
+
module Ruboty
|
|
14
|
+
module GithubActions
|
|
15
|
+
end
|
|
16
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: ruboty-github_actions
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- tomoasleep
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: octokit
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '6.0'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '6.0'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: jwt
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '2.0'
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '2.0'
|
|
40
|
+
- !ruby/object:Gem::Dependency
|
|
41
|
+
name: ruboty
|
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - ">="
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '1.3'
|
|
47
|
+
type: :runtime
|
|
48
|
+
prerelease: false
|
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - ">="
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '1.3'
|
|
54
|
+
description: A ruboty plugin to trigger GitHub Actions workflows via chat
|
|
55
|
+
executables: []
|
|
56
|
+
extensions: []
|
|
57
|
+
extra_rdoc_files: []
|
|
58
|
+
files:
|
|
59
|
+
- README.md
|
|
60
|
+
- lib/ruboty-github_actions.rb
|
|
61
|
+
- lib/ruboty/github_actions.rb
|
|
62
|
+
- lib/ruboty/github_actions/actions/client.rb
|
|
63
|
+
- lib/ruboty/github_actions/actions/run_workflow.rb
|
|
64
|
+
- lib/ruboty/github_actions/actions/set_credential.rb
|
|
65
|
+
- lib/ruboty/github_actions/credential.rb
|
|
66
|
+
- lib/ruboty/github_actions/handlers/github_actions.rb
|
|
67
|
+
- lib/ruboty/github_actions/version.rb
|
|
68
|
+
homepage: https://github.com/tomoasleep/ruboty-github_actions
|
|
69
|
+
licenses:
|
|
70
|
+
- MIT
|
|
71
|
+
metadata: {}
|
|
72
|
+
rdoc_options: []
|
|
73
|
+
require_paths:
|
|
74
|
+
- lib
|
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
76
|
+
requirements:
|
|
77
|
+
- - ">="
|
|
78
|
+
- !ruby/object:Gem::Version
|
|
79
|
+
version: '3.0'
|
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
|
+
requirements:
|
|
82
|
+
- - ">="
|
|
83
|
+
- !ruby/object:Gem::Version
|
|
84
|
+
version: '0'
|
|
85
|
+
requirements: []
|
|
86
|
+
rubygems_version: 4.0.11
|
|
87
|
+
specification_version: 4
|
|
88
|
+
summary: Run GitHub Actions workflows from ruboty
|
|
89
|
+
test_files: []
|