cron_for_github 0.0.1.beta → 1.0.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 +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +60 -0
- data/lib/cron_for_github.rb +1 -0
- data/lib/cron_for_github/cli.rb +35 -14
- data/lib/cron_for_github/client.rb +32 -3
- data/lib/cron_for_github/error.rb +2 -0
- data/lib/cron_for_github/ping.rb +26 -14
- data/lib/cron_for_github/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74c0e745ecd904226fb3c45f2fa28386c89d364f
|
4
|
+
data.tar.gz: ff1feb1ed75c5029bff443392cc02cdd613967ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef8c3e377d4095d3101bef4b02a74fde174dce4b291df685ab28328058f9be902cab261576a0d293c526cde469294fcf7e4c9faee02077156fb64cdcf5c9f46d
|
7
|
+
data.tar.gz: e848b6e38465db16c3955ddf97d8f71c85a85a6d5514ae9d33f29d8c0e4a2c7ca2dbeccccbde1d0305582a71353be6bf7ed2c1a84f038bc2e70e3b7a2814c2bc
|
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -5,16 +5,72 @@
|
|
5
5
|
|
6
6
|
## Usage
|
7
7
|
|
8
|
+
**Cron for GitHub**, you can kick GitHub by creating branch. This also wakes web-hooks up!
|
9
|
+
|
10
|
+
```
|
11
|
+
$ cron-for-github ping --slug=YOU/YOUR_REPO
|
12
|
+
```
|
13
|
+
|
14
|
+
After few seconds, your repo has a new branch `cron_for_github/da0535a2-9523-42e3-bae2-a2e682b2f437`.
|
15
|
+
`da0535a2-9523-42e3-bae2-a2e682b2f437` is uuid.
|
16
|
+
|
8
17
|
## Command
|
9
18
|
|
19
|
+
```
|
20
|
+
Commands:
|
21
|
+
cron-for-github clear --slug=SLUG # Delete cron branches
|
22
|
+
cron-for-github help [COMMAND] # Describe available commands or one specific command
|
23
|
+
cron-for-github ping --slug=SLUG # Kick cron
|
24
|
+
cron-for-github version # Show the CronForGithub version
|
25
|
+
|
26
|
+
Usage:
|
27
|
+
cron-for-github ping --slug=SLUG
|
28
|
+
|
29
|
+
Options:
|
30
|
+
[--debug], [--no-debug]
|
31
|
+
[--verbose], [--no-verbose]
|
32
|
+
--slug=SLUG
|
33
|
+
[--namespace=NAMESPACE]
|
34
|
+
# Default: cron_for_github
|
35
|
+
[--base=BASE]
|
36
|
+
# Default: master
|
37
|
+
|
38
|
+
Kick cron
|
39
|
+
|
40
|
+
Usage:
|
41
|
+
cron-for-github clear --slug=SLUG
|
42
|
+
|
43
|
+
Options:
|
44
|
+
[--debug], [--no-debug]
|
45
|
+
[--verbose], [--no-verbose]
|
46
|
+
--slug=SLUG
|
47
|
+
[--namespace=NAMESPACE]
|
48
|
+
# Default: cron_for_github
|
49
|
+
|
50
|
+
Delete cron branches
|
51
|
+
```
|
52
|
+
|
10
53
|
## VS.
|
11
54
|
|
55
|
+
### [traviscron.pythonanywhere.com](http://traviscron.pythonanywhere.com/)
|
56
|
+
|
57
|
+
Good service for Travis-CI. This requires form submitting, and only for Travis-CI.
|
58
|
+
|
12
59
|
### [Tachikoma.io](http://tachikoma.io)
|
13
60
|
|
14
61
|
Dependency Update as a Service.
|
15
62
|
This is only dependency update, so problem specific SaaS.
|
16
63
|
If you NEVER want to maintenance your server (include Heroku), Tachikoma.io suits you.
|
17
64
|
|
65
|
+
### [zapier](https://zapier.com/)/[ifttt](https://ifttt.com/)
|
66
|
+
|
67
|
+
I don't know how to achieve yet.
|
68
|
+
|
69
|
+
### Build periodically travis-ci/travis-ci
|
70
|
+
|
71
|
+
We solve this! :)
|
72
|
+
[Build periodically travis-ci/travis-ci](https://github.com/travis-ci/travis-ci/issues/582)
|
73
|
+
|
18
74
|
## Installation
|
19
75
|
|
20
76
|
Add this line to your application's Gemfile:
|
@@ -31,6 +87,10 @@ Or install it yourself as:
|
|
31
87
|
|
32
88
|
$ gem install cron_for_github
|
33
89
|
|
90
|
+
## Requirement
|
91
|
+
|
92
|
+
Set `GITHUB_ACCESS_TOKEN=__your_access_token__` to your environment variable.
|
93
|
+
|
34
94
|
## Development
|
35
95
|
|
36
96
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment. Run `bundle exec cron_for_github` to use the code located in this directory, ignoring other installed copies of this gem.
|
data/lib/cron_for_github.rb
CHANGED
@@ -8,6 +8,7 @@ require 'cron_for_github/ping'
|
|
8
8
|
require 'cron_for_github/version'
|
9
9
|
|
10
10
|
module CronForGithub
|
11
|
+
ISSUE_URL = 'https://github.com/packsaddle/ruby-cron_for_github/issues/new'
|
11
12
|
def self.default_logger
|
12
13
|
logger = Logger.new(STDERR)
|
13
14
|
logger.progname = 'CronForGithub'
|
data/lib/cron_for_github/cli.rb
CHANGED
@@ -19,14 +19,16 @@ module CronForGithub
|
|
19
19
|
option :slug, type: :string, required: true
|
20
20
|
option :namespace, type: :string, default: Ping::NAMESPACE
|
21
21
|
def clear
|
22
|
-
|
23
|
-
logger.level = Logger::DEBUG
|
24
|
-
elsif options[:verbose]
|
25
|
-
logger.level = Logger::INFO
|
26
|
-
end
|
27
|
-
logger.debug(options)
|
22
|
+
setup_logger(options)
|
28
23
|
|
29
|
-
|
24
|
+
params = {
|
25
|
+
slug: options[:slug],
|
26
|
+
namespace: options[:namespace]
|
27
|
+
}
|
28
|
+
Ping.new.clear(params)
|
29
|
+
rescue StandardError => e
|
30
|
+
suggest_messages(options)
|
31
|
+
raise e
|
30
32
|
end
|
31
33
|
|
32
34
|
desc 'ping', 'Kick cron'
|
@@ -36,20 +38,39 @@ module CronForGithub
|
|
36
38
|
option :namespace, type: :string, default: Ping::NAMESPACE
|
37
39
|
option :base, type: :string, default: Ping::BASE
|
38
40
|
def ping
|
39
|
-
|
40
|
-
logger.level = Logger::DEBUG
|
41
|
-
elsif options[:verbose]
|
42
|
-
logger.level = Logger::INFO
|
43
|
-
end
|
44
|
-
logger.debug(options)
|
41
|
+
setup_logger(options)
|
45
42
|
|
46
|
-
|
43
|
+
params = {
|
44
|
+
slug: options[:slug],
|
45
|
+
namespace: options[:namespace],
|
46
|
+
base: options[:base]
|
47
|
+
}
|
48
|
+
Ping.new.ping(params)
|
49
|
+
rescue StandardError => e
|
50
|
+
suggest_messages(options)
|
51
|
+
raise e
|
47
52
|
end
|
48
53
|
|
49
54
|
no_commands do
|
50
55
|
def logger
|
51
56
|
::CronForGithub.logger
|
52
57
|
end
|
58
|
+
|
59
|
+
def setup_logger(options)
|
60
|
+
if options[:debug]
|
61
|
+
logger.level = Logger::DEBUG
|
62
|
+
elsif options[:verbose]
|
63
|
+
logger.level = Logger::INFO
|
64
|
+
end
|
65
|
+
logger.debug(options)
|
66
|
+
end
|
67
|
+
|
68
|
+
def suggest_messages(options)
|
69
|
+
logger.error 'Please report from here:'
|
70
|
+
logger.error ISSUE_URL
|
71
|
+
logger.error 'options:'
|
72
|
+
logger.error options
|
73
|
+
end
|
53
74
|
end
|
54
75
|
end
|
55
76
|
end
|
@@ -5,25 +5,54 @@ module CronForGithub
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def latest_sha(slug, head_ref)
|
8
|
-
client.ref(slug, head_ref)
|
8
|
+
response = client.ref(slug, head_ref)
|
9
|
+
logger.debug(response)
|
10
|
+
response.object.sha
|
9
11
|
end
|
10
12
|
|
11
13
|
def create_ref(slug, expected_ref, sha)
|
12
|
-
|
14
|
+
logger.info('ref creating')
|
15
|
+
logger.info(slug: slug, ref: expected_ref)
|
16
|
+
return_ref = client.create_ref(slug, expected_ref, sha)
|
17
|
+
logger.info('ref created')
|
18
|
+
logger.debug(return_ref)
|
19
|
+
return_ref
|
13
20
|
end
|
14
21
|
|
15
22
|
def refs(slug, refs_prefix)
|
16
23
|
client
|
17
24
|
.refs(slug, refs_prefix)
|
18
25
|
.map(&:ref)
|
26
|
+
.map { |ref| remove_prefix_refs(ref) }
|
27
|
+
rescue Octokit::NotFound
|
28
|
+
logger.info('no repos exist:')
|
29
|
+
logger.info(slug: slug, refs_prefix: refs_prefix)
|
30
|
+
[]
|
19
31
|
end
|
20
32
|
|
21
33
|
def delete_ref(slug, ref)
|
22
|
-
|
34
|
+
logger.info('ref deleting')
|
35
|
+
logger.info(slug: slug, ref: ref)
|
36
|
+
return_ref = client.delete_ref(slug, ref)
|
37
|
+
logger.info('ref deleted')
|
38
|
+
logger.debug(return_ref)
|
39
|
+
return_ref
|
23
40
|
end
|
24
41
|
|
25
42
|
def access_token
|
26
43
|
ENV['GITHUB_ACCESS_TOKEN']
|
27
44
|
end
|
45
|
+
|
46
|
+
# remove refs/ from "refs/heads/ping/foo-bar"
|
47
|
+
def remove_prefix_refs(ref)
|
48
|
+
regex = %r{\Arefs/(?<stripped_ref>.+)\Z}
|
49
|
+
match = regex.match(ref)
|
50
|
+
fail InvalidRefPrefixError, "ref: #{ref}" unless match
|
51
|
+
match[:stripped_ref]
|
52
|
+
end
|
53
|
+
|
54
|
+
def logger
|
55
|
+
::CronForGithub.logger
|
56
|
+
end
|
28
57
|
end
|
29
58
|
end
|
data/lib/cron_for_github/ping.rb
CHANGED
@@ -1,13 +1,24 @@
|
|
1
1
|
module CronForGithub
|
2
2
|
class Ping
|
3
|
-
NAMESPACE = '
|
3
|
+
NAMESPACE = 'cron_for_github'
|
4
4
|
BASE = 'master'
|
5
|
+
RESERVED_REFS = %w(
|
6
|
+
tags
|
7
|
+
gh-pages
|
8
|
+
master
|
9
|
+
branches
|
10
|
+
trunk
|
11
|
+
feature
|
12
|
+
develop
|
13
|
+
release
|
14
|
+
hotfix
|
15
|
+
)
|
5
16
|
|
6
17
|
def ping(params)
|
7
18
|
client = Client.new
|
8
19
|
slug = decide_slug(params[:slug])
|
9
20
|
head_ref = decide_head_ref(params[:base])
|
10
|
-
cron_ref = decide_cron_ref(params[:namespace])
|
21
|
+
cron_ref = decide_cron_ref(params[:namespace], __method__)
|
11
22
|
|
12
23
|
latest_sha = client.latest_sha(slug, head_ref)
|
13
24
|
client.create_ref(slug, cron_ref, latest_sha)
|
@@ -22,32 +33,33 @@ module CronForGithub
|
|
22
33
|
"heads/#{text}"
|
23
34
|
end
|
24
35
|
|
25
|
-
def decide_cron_ref(text)
|
26
|
-
text
|
27
|
-
"heads/#{text}/#{SecureRandom.uuid}"
|
36
|
+
def decide_cron_ref(text, caller = nil)
|
37
|
+
"#{decide_cron_ref_prefix(text, caller)}#{SecureRandom.uuid}"
|
28
38
|
end
|
29
39
|
|
30
40
|
def clear(params)
|
31
41
|
client = Client.new
|
32
42
|
slug = decide_slug(params[:slug])
|
33
|
-
|
43
|
+
cron_ref_prefix = decide_cron_ref_prefix(params[:namespace])
|
34
44
|
|
35
|
-
cron_refs = client.refs(slug,
|
45
|
+
cron_refs = client.refs(slug, cron_ref_prefix)
|
36
46
|
cron_refs
|
37
|
-
.map { |ref| convert_ref(ref) }
|
38
47
|
.each do |clear_ref|
|
39
48
|
client.delete_ref(slug, clear_ref)
|
40
49
|
end
|
41
50
|
end
|
42
51
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
def decide_cron_refs_prefix(text)
|
52
|
+
def decide_cron_ref_prefix(text, caller = nil)
|
53
|
+
if caller != :ping && RESERVED_REFS.include?(text)
|
54
|
+
fail ReservedNamespaceError, \
|
55
|
+
%("#{text}" is reserved. List: #{RESERVED_REFS.join(', ')})
|
56
|
+
end
|
49
57
|
text = NAMESPACE if !text || text.empty?
|
50
58
|
"heads/#{text}/"
|
51
59
|
end
|
60
|
+
|
61
|
+
def logger
|
62
|
+
::CronForGithub.logger
|
63
|
+
end
|
52
64
|
end
|
53
65
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cron_for_github
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sanemat
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -90,6 +90,7 @@ extra_rdoc_files: []
|
|
90
90
|
files:
|
91
91
|
- ".gitignore"
|
92
92
|
- ".rubocop.yml"
|
93
|
+
- CHANGELOG.md
|
93
94
|
- CODE_OF_CONDUCT.md
|
94
95
|
- Gemfile
|
95
96
|
- LICENSE.txt
|
@@ -120,9 +121,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
120
121
|
version: '0'
|
121
122
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
123
|
requirements:
|
123
|
-
- - "
|
124
|
+
- - ">="
|
124
125
|
- !ruby/object:Gem::Version
|
125
|
-
version:
|
126
|
+
version: '0'
|
126
127
|
requirements: []
|
127
128
|
rubyforge_project:
|
128
129
|
rubygems_version: 2.4.5
|