jackal-github-kit 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/CHANGELOG.md +2 -0
- data/CONTRIBUTING.md +25 -0
- data/LICENSE +13 -0
- data/README.md +86 -0
- data/jackal-github-kit.gemspec +16 -0
- data/lib/jackal-github-kit.rb +9 -0
- data/lib/jackal-github-kit/hubber.rb +118 -0
- data/lib/jackal-github-kit/version.rb +6 -0
- metadata +80 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d03126fcac1f91bcbff8399b1d7cfd5fcc2f8c00
|
4
|
+
data.tar.gz: 8e4937d981f0f9bbc8bf6aa87e97975b99d85c86
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 275b6804fff1b98126084b1c04c34c0f8590181698fd57222a86e7c9bb9e8a2b1571c1187f70ea062ade8d016e63c1e098d2c650351b65ca6f7863614020c58b
|
7
|
+
data.tar.gz: 642d63754ed446f144843d86d1d803fb34c8ac702879068877a6a334018a0d00836d5f4fcaea58bfe314215406483a2c369fca18cc226877162a195877fc8c8d
|
data/CHANGELOG.md
ADDED
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# Contributing
|
2
|
+
|
3
|
+
## Branches
|
4
|
+
|
5
|
+
### `master` branch
|
6
|
+
|
7
|
+
The master branch is the current stable released version.
|
8
|
+
|
9
|
+
### `develop` branch
|
10
|
+
|
11
|
+
The develop branch is the current edge of development.
|
12
|
+
|
13
|
+
## Pull requests
|
14
|
+
|
15
|
+
* https://github.com/carnivore-rb/jackal-github-kit/pulls
|
16
|
+
|
17
|
+
Please base all pull requests of the `develop` branch. Merges to
|
18
|
+
`master` only occur through the `develop` branch. Pull requests
|
19
|
+
based on `master` will likely be cherry picked.
|
20
|
+
|
21
|
+
## Issues
|
22
|
+
|
23
|
+
Need to report an issue? Use the github issues:
|
24
|
+
|
25
|
+
* https://github.com/carnivore-rb/jackal-github-kit/issues
|
data/LICENSE
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright 2014 Chris Roberts
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
# Jackal GitHub Kit
|
2
|
+
|
3
|
+
Provides communications interface with GitHub.
|
4
|
+
|
5
|
+
## Supported communications
|
6
|
+
|
7
|
+
* Repository commit comment
|
8
|
+
* Repository status
|
9
|
+
|
10
|
+
## Configuration
|
11
|
+
|
12
|
+
Access tokens are used for access to GitHub. Configuration can
|
13
|
+
be provided via direct configuration:
|
14
|
+
|
15
|
+
```json
|
16
|
+
{
|
17
|
+
"jackal": {
|
18
|
+
"github_kit": {
|
19
|
+
"config": {
|
20
|
+
"github": {
|
21
|
+
"access_token": TOKEN
|
22
|
+
}
|
23
|
+
}
|
24
|
+
}
|
25
|
+
}
|
26
|
+
}
|
27
|
+
```
|
28
|
+
|
29
|
+
or it can be provided via application level configuration:
|
30
|
+
|
31
|
+
```json
|
32
|
+
{
|
33
|
+
"jackal": {
|
34
|
+
"github": {
|
35
|
+
"access_token": ACCESS_TOKEN
|
36
|
+
}
|
37
|
+
}
|
38
|
+
}
|
39
|
+
```
|
40
|
+
|
41
|
+
## Payload structure
|
42
|
+
|
43
|
+
### Repository commit comment
|
44
|
+
|
45
|
+
```json
|
46
|
+
{
|
47
|
+
...
|
48
|
+
"data": {
|
49
|
+
"github_kit": {
|
50
|
+
"commit_comment": {
|
51
|
+
"repository": REPOSITORY_FULL_NAME,
|
52
|
+
"reference": COMMIT_SHA,
|
53
|
+
"message": MESSAGE_TEXT
|
54
|
+
}
|
55
|
+
}
|
56
|
+
}
|
57
|
+
...
|
58
|
+
}
|
59
|
+
```
|
60
|
+
|
61
|
+
### Repository status
|
62
|
+
|
63
|
+
```json
|
64
|
+
{
|
65
|
+
...
|
66
|
+
"data": {
|
67
|
+
"github_kit": {
|
68
|
+
"status": {
|
69
|
+
"repository": REPOSITORY_FULL_NAME,
|
70
|
+
"reference": COMMIT_SHA,
|
71
|
+
"state": STATE,
|
72
|
+
"extras": {
|
73
|
+
"description": DESCRIPTION_TEXT,
|
74
|
+
"target_url": STATUS_URL
|
75
|
+
}
|
76
|
+
}
|
77
|
+
}
|
78
|
+
}
|
79
|
+
...
|
80
|
+
}
|
81
|
+
```
|
82
|
+
|
83
|
+
# Info
|
84
|
+
|
85
|
+
* Repository: https://github.com/carnivore-rb/jackal-github-kit
|
86
|
+
* IRC: Freenode @ #carnivore
|
@@ -0,0 +1,16 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__)) + '/lib/'
|
2
|
+
require 'jackal-github-kit/version'
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = 'jackal-github-kit'
|
5
|
+
s.version = Jackal::GithubKit::VERSION.version
|
6
|
+
s.summary = 'Message processing helper'
|
7
|
+
s.author = 'Chris Roberts'
|
8
|
+
s.email = 'code@chrisroberts.org'
|
9
|
+
s.homepage = 'https://github.com/carnivore-rb/jackal-github-kit'
|
10
|
+
s.description = 'GitHub interaction helper'
|
11
|
+
s.require_path = 'lib'
|
12
|
+
s.license = 'Apache 2.0'
|
13
|
+
s.add_dependency 'jackal'
|
14
|
+
s.add_dependency 'octokit'
|
15
|
+
s.files = Dir['lib/**/*'] + %w(jackal-github-kit.gemspec README.md CHANGELOG.md CONTRIBUTING.md LICENSE)
|
16
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
require 'jackal-github-kit'
|
2
|
+
|
3
|
+
module Jackal
|
4
|
+
module GithubKit
|
5
|
+
class Hubber < Callback
|
6
|
+
|
7
|
+
# Setup callback
|
8
|
+
def setup(*_)
|
9
|
+
require 'octokit'
|
10
|
+
end
|
11
|
+
|
12
|
+
# Determine validity of message
|
13
|
+
#
|
14
|
+
# @param message [Carnivore::Message]
|
15
|
+
# @return [Truthy, Falsey]
|
16
|
+
def valid?(message)
|
17
|
+
super do |payload|
|
18
|
+
payload.get(:data, :github_kit, :commit_comment) ||
|
19
|
+
payload.get(:data, :github_kit, :status)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# @return [Octokit::Client]
|
24
|
+
def github_client
|
25
|
+
memoize(:github_client) do
|
26
|
+
gh_conf = {
|
27
|
+
:access_token => config.fetch(:github, :access_token,
|
28
|
+
app_config.get(:github, :access_token)
|
29
|
+
)
|
30
|
+
}
|
31
|
+
Octokit::Client.new(gh_conf)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# Add comment to GitHub commit SHA
|
36
|
+
#
|
37
|
+
# @param message [Carnivore::Message]
|
38
|
+
def execute(message)
|
39
|
+
failure_wrap(message) do |payload|
|
40
|
+
write_release(payload) if payload.get(:data, :github_kit, :release)
|
41
|
+
write_commit_comment(payload) if payload.get(:data, :github_kit, :commit_comment)
|
42
|
+
write_status(payload) if payload.get(:data, :github_kit, :status)
|
43
|
+
job_completed(:github_kit, payload, message)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Write comment to GitHub SHA reference
|
48
|
+
#
|
49
|
+
# @param payload [Smash]
|
50
|
+
# @return [TrueClass]
|
51
|
+
def write_commit_comment(payload)
|
52
|
+
comment = payload[:data][:github_kit].delete(:commit_comment)
|
53
|
+
info 'Writing commit comment to GitHub'
|
54
|
+
debug "GitHub commit comment: #{comment.inspect}"
|
55
|
+
github_client.create_commit_comment(
|
56
|
+
comment[:repository],
|
57
|
+
comment[:reference],
|
58
|
+
comment[:message]
|
59
|
+
)
|
60
|
+
true
|
61
|
+
end
|
62
|
+
|
63
|
+
# Write status of pull request to github
|
64
|
+
#
|
65
|
+
# @param payload [Smash]
|
66
|
+
# @return [TrueClass]
|
67
|
+
def write_status(payload)
|
68
|
+
status = payload[:data][:github_kit].delete(:status)
|
69
|
+
info 'Writing repository status to GitHub'
|
70
|
+
debug "GitHub repository status: #{status.inspect}"
|
71
|
+
github_client.create_status(
|
72
|
+
status[:repository],
|
73
|
+
status[:reference],
|
74
|
+
status[:state].to_sym,
|
75
|
+
status.fetch(:extras, Smash.new)
|
76
|
+
)
|
77
|
+
true
|
78
|
+
end
|
79
|
+
|
80
|
+
# Write release to github
|
81
|
+
#
|
82
|
+
# @param payload [Smash]
|
83
|
+
# @return [TrueClass]
|
84
|
+
def write_release(payload)
|
85
|
+
info 'Creating new release on GitHub'
|
86
|
+
rel = payload[:data][:github_kit].delete(:release)
|
87
|
+
release = github_client.create_release(
|
88
|
+
rel[:repository],
|
89
|
+
rel[:tag_name],
|
90
|
+
:name => rel[:name],
|
91
|
+
:target_commitish => rel[:reference],
|
92
|
+
:prerelease => rel[:prerelease],
|
93
|
+
:body => rel[:body]
|
94
|
+
)
|
95
|
+
|
96
|
+
api_release_url = release.rels[:self].href
|
97
|
+
public_release_url = release.rels[:html].href
|
98
|
+
|
99
|
+
info 'New release created on GitHub. Uploading assets.'
|
100
|
+
rel[:assets].each do |asset|
|
101
|
+
debug "Uploading release asset - #{asset}"
|
102
|
+
github_client.upload_asset(
|
103
|
+
api_release_url,
|
104
|
+
asset_store.get(asset),
|
105
|
+
:name => asset.sub(/^.+?_/, ''),
|
106
|
+
:content_type => 'application/octet-stream'
|
107
|
+
)
|
108
|
+
debug "Completed release asset upload - #{asset}"
|
109
|
+
end
|
110
|
+
|
111
|
+
payload.set(:data, :github_kit, :release, :api_url, api_release_url)
|
112
|
+
payload.set(:data, :github_kit, :release, :public_url, public_release_url)
|
113
|
+
true
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jackal-github-kit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chris Roberts
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: jackal
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: octokit
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: GitHub interaction helper
|
42
|
+
email: code@chrisroberts.org
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- CHANGELOG.md
|
48
|
+
- CONTRIBUTING.md
|
49
|
+
- LICENSE
|
50
|
+
- README.md
|
51
|
+
- jackal-github-kit.gemspec
|
52
|
+
- lib/jackal-github-kit.rb
|
53
|
+
- lib/jackal-github-kit/hubber.rb
|
54
|
+
- lib/jackal-github-kit/version.rb
|
55
|
+
homepage: https://github.com/carnivore-rb/jackal-github-kit
|
56
|
+
licenses:
|
57
|
+
- Apache 2.0
|
58
|
+
metadata: {}
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
requirements: []
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 2.2.2
|
76
|
+
signing_key:
|
77
|
+
specification_version: 4
|
78
|
+
summary: Message processing helper
|
79
|
+
test_files: []
|
80
|
+
has_rdoc:
|