cron_for_github 0.0.1.beta

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 03d221de2836e1a764f143f35480be31097a8ebe
4
+ data.tar.gz: 250d06261a5764466e1c4fc5f30d81d481d06f11
5
+ SHA512:
6
+ metadata.gz: 8de62dd929755ce43212032717b78b579beb1d3b05328b655ea0061dc80896ee0a515b55f9a2bfd2072db2c5fd659eac3bd1ebbd194ff1e5f61e213a9215392c
7
+ data.tar.gz: f06aed51573f5657e8c0d2a9db18cec464335a876d598eb6d26d5d48713747885aef1fb32ff8ee9bca1be741d7591eac49aa200aa59faa8074697adc5670eb45
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rubocop.yml ADDED
@@ -0,0 +1,17 @@
1
+ AllCops:
2
+ Exclude:
3
+ - 'bundle_bin/*'
4
+ - 'vendor/bundle/**/*'
5
+
6
+ Style/Documentation:
7
+ Enabled: false
8
+
9
+ Metrics/LineLength:
10
+ Max: 100
11
+
12
+ Style/FileName:
13
+ Exclude:
14
+ - exe/*
15
+
16
+ Style/RegexpLiteral:
17
+ MaxSlashes: 0
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cron_for_github.gemspec
4
+ gemspec
5
+ gem 'byebug' if RUBY_VERSION >= '2.0.0'
6
+ gem 'pry'
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 sanemat
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # CronForGithub
2
+
3
+ [![Gem Version](http://img.shields.io/gem/v/cron_for_github.svg?style=flat)](http://badge.fury.io/rb/cron_for_github)
4
+ [![Build Status](http://img.shields.io/travis/packsaddle/ruby-cron_for_github/master.svg?style=flat)](https://travis-ci.org/packsaddle/ruby-cron_for_github)
5
+
6
+ ## Usage
7
+
8
+ ## Command
9
+
10
+ ## VS.
11
+
12
+ ### [Tachikoma.io](http://tachikoma.io)
13
+
14
+ Dependency Update as a Service.
15
+ This is only dependency update, so problem specific SaaS.
16
+ If you NEVER want to maintenance your server (include Heroku), Tachikoma.io suits you.
17
+
18
+ ## Installation
19
+
20
+ Add this line to your application's Gemfile:
21
+
22
+ ```ruby
23
+ gem 'cron_for_github'
24
+ ```
25
+
26
+ And then execute:
27
+
28
+ $ bundle
29
+
30
+ Or install it yourself as:
31
+
32
+ $ gem install cron_for_github
33
+
34
+ ## Development
35
+
36
+ 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.
37
+
38
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
39
+
40
+ ## Contributing
41
+
42
+ 1. Fork it ( https://github.com/ruby-cron_for_github/cron_for_github/fork )
43
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
44
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
45
+ 4. Push to the branch (`git push origin my-new-feature`)
46
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << 'test'
6
+ t.test_files = FileList['test/**/test*.rb']
7
+ t.verbose = true
8
+ end
9
+
10
+ task default: :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'cron_for_github'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,38 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cron_for_github/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'cron_for_github'
8
+ spec.version = CronForGithub::VERSION
9
+ spec.authors = ['sanemat']
10
+ spec.email = ['o.gata.ken@gmail.com']
11
+
12
+ spec.summary = 'Cron for GitHub'
13
+ spec.description = 'The interval build comes.'
14
+ spec.homepage = 'https://github.com/packsaddle/ruby-cron_for_github'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = \
18
+ `git ls-files -z`
19
+ .split("\x0")
20
+ .reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ .reject do |f|
22
+ [
23
+ '.travis.yml',
24
+ 'circle.yml',
25
+ '.tachikoma.yml'
26
+ ].include?(f)
27
+ end
28
+ spec.bindir = 'exe'
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ['lib']
31
+
32
+ spec.add_runtime_dependency 'thor'
33
+ spec.add_runtime_dependency 'octokit'
34
+
35
+ spec.add_development_dependency 'bundler', '~> 1.8'
36
+ spec.add_development_dependency 'rake', '~> 10.0'
37
+ spec.add_development_dependency 'test-unit'
38
+ end
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'cron_for_github'
4
+ require 'cron_for_github/cli'
5
+ CronForGithub::CLI.start(ARGV)
@@ -0,0 +1,26 @@
1
+ require 'logger'
2
+ require 'octokit'
3
+ require 'securerandom'
4
+
5
+ require 'cron_for_github/client'
6
+ require 'cron_for_github/error'
7
+ require 'cron_for_github/ping'
8
+ require 'cron_for_github/version'
9
+
10
+ module CronForGithub
11
+ def self.default_logger
12
+ logger = Logger.new(STDERR)
13
+ logger.progname = 'CronForGithub'
14
+ logger.level = Logger::WARN
15
+ logger
16
+ end
17
+
18
+ def self.logger
19
+ return @logger if @logger
20
+ @logger = default_logger
21
+ end
22
+
23
+ class << self
24
+ attr_writer :logger
25
+ end
26
+ end
@@ -0,0 +1,55 @@
1
+ require 'thor'
2
+
3
+ module CronForGithub
4
+ class CLI < Thor
5
+ def self.exit_on_failure?
6
+ true
7
+ end
8
+
9
+ desc 'version', 'Show the CronForGithub version'
10
+ map %w(-v --version) => :version
11
+
12
+ def version
13
+ puts "CronForGithub version #{::CronForGithub::VERSION}"
14
+ end
15
+
16
+ desc 'clear', 'Delete cron branches'
17
+ option :debug, type: :boolean, default: false
18
+ option :verbose, type: :boolean, default: false
19
+ option :slug, type: :string, required: true
20
+ option :namespace, type: :string, default: Ping::NAMESPACE
21
+ def clear
22
+ if options[:debug]
23
+ logger.level = Logger::DEBUG
24
+ elsif options[:verbose]
25
+ logger.level = Logger::INFO
26
+ end
27
+ logger.debug(options)
28
+
29
+ Ping.new.clear(options.select { |k, _| [:slug, :namespace].include?(k) })
30
+ end
31
+
32
+ desc 'ping', 'Kick cron'
33
+ option :debug, type: :boolean, default: false
34
+ option :verbose, type: :boolean, default: false
35
+ option :slug, type: :string, required: true
36
+ option :namespace, type: :string, default: Ping::NAMESPACE
37
+ option :base, type: :string, default: Ping::BASE
38
+ def ping
39
+ if options[:debug]
40
+ logger.level = Logger::DEBUG
41
+ elsif options[:verbose]
42
+ logger.level = Logger::INFO
43
+ end
44
+ logger.debug(options)
45
+
46
+ Ping.new.ping(options.select { |k, _| [:slug, :namespace, :base].include?(k) })
47
+ end
48
+
49
+ no_commands do
50
+ def logger
51
+ ::CronForGithub.logger
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,29 @@
1
+ module CronForGithub
2
+ class Client
3
+ def client
4
+ @client ||= Octokit::Client.new(access_token: access_token)
5
+ end
6
+
7
+ def latest_sha(slug, head_ref)
8
+ client.ref(slug, head_ref).object.sha
9
+ end
10
+
11
+ def create_ref(slug, expected_ref, sha)
12
+ client.create_ref(slug, expected_ref, sha)
13
+ end
14
+
15
+ def refs(slug, refs_prefix)
16
+ client
17
+ .refs(slug, refs_prefix)
18
+ .map(&:ref)
19
+ end
20
+
21
+ def delete_ref(slug, ref)
22
+ client.delete_ref(slug, ref)
23
+ end
24
+
25
+ def access_token
26
+ ENV['GITHUB_ACCESS_TOKEN']
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,4 @@
1
+ module CronForGithub
2
+ class CronForGithubError < StandardError; end
3
+ class NeedSlugError < CronForGithubError; end
4
+ end
@@ -0,0 +1,53 @@
1
+ module CronForGithub
2
+ class Ping
3
+ NAMESPACE = 'cron'
4
+ BASE = 'master'
5
+
6
+ def ping(params)
7
+ client = Client.new
8
+ slug = decide_slug(params[:slug])
9
+ head_ref = decide_head_ref(params[:base])
10
+ cron_ref = decide_cron_ref(params[:namespace])
11
+
12
+ latest_sha = client.latest_sha(slug, head_ref)
13
+ client.create_ref(slug, cron_ref, latest_sha)
14
+ end
15
+
16
+ def decide_slug(text)
17
+ text
18
+ end
19
+
20
+ def decide_head_ref(text)
21
+ text = BASE if !text || text.empty?
22
+ "heads/#{text}"
23
+ end
24
+
25
+ def decide_cron_ref(text)
26
+ text = NAMESPACE if !text || text.empty?
27
+ "heads/#{text}/#{SecureRandom.uuid}"
28
+ end
29
+
30
+ def clear(params)
31
+ client = Client.new
32
+ slug = decide_slug(params[:slug])
33
+ cron_refs_prefix = decide_cron_refs_prefix(params[:namespace])
34
+
35
+ cron_refs = client.refs(slug, cron_refs_prefix)
36
+ cron_refs
37
+ .map { |ref| convert_ref(ref) }
38
+ .each do |clear_ref|
39
+ client.delete_ref(slug, clear_ref)
40
+ end
41
+ end
42
+
43
+ # remove refs/ from "refs/heads/ping/foo-bar"
44
+ def convert_ref(ref)
45
+ ref
46
+ end
47
+
48
+ def decide_cron_refs_prefix(text)
49
+ text = NAMESPACE if !text || text.empty?
50
+ "heads/#{text}/"
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,3 @@
1
+ module CronForGithub
2
+ VERSION = '0.0.1.beta'
3
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cron_for_github
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.beta
5
+ platform: ruby
6
+ authors:
7
+ - sanemat
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-03-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
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
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.8'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.8'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: test-unit
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: The interval build comes.
84
+ email:
85
+ - o.gata.ken@gmail.com
86
+ executables:
87
+ - cron-for-github
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rubocop.yml"
93
+ - CODE_OF_CONDUCT.md
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - bin/console
99
+ - bin/setup
100
+ - cron_for_github.gemspec
101
+ - exe/cron-for-github
102
+ - lib/cron_for_github.rb
103
+ - lib/cron_for_github/cli.rb
104
+ - lib/cron_for_github/client.rb
105
+ - lib/cron_for_github/error.rb
106
+ - lib/cron_for_github/ping.rb
107
+ - lib/cron_for_github/version.rb
108
+ homepage: https://github.com/packsaddle/ruby-cron_for_github
109
+ licenses:
110
+ - MIT
111
+ metadata: {}
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">"
124
+ - !ruby/object:Gem::Version
125
+ version: 1.3.1
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 2.4.5
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: Cron for GitHub
132
+ test_files: []