ruboty-packman 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 68256f0d58eef17fb1ce4aa6adc1dd1b90f7b366280f51d58e59913d00d3b68c
4
+ data.tar.gz: 1ae0dad8e9271590d1c3f1797db9a3cf0fdd40c85263901b0bf445f16e861808
5
+ SHA512:
6
+ metadata.gz: eef3381f1e9a6bc0c778987848bfce640a3c547565c7b05cab3a9901ab44b6f19b8a9c6c65eba114faa3adcc176b587a7ccd1a11e3da3db229027b04f3f9695d
7
+ data.tar.gz: 412b8a9d020b9808aba18558e0e6aee45370d5b50d8f42921f6f4f850cbf1bf53a95638cbfb509de5498e0a98fde346b07e60ad729e3d8b71c3187acea6f6192
data/.env.sample ADDED
@@ -0,0 +1,4 @@
1
+ PACKMAN_REPOS_DIR=
2
+ GITHUB_TOKEN=
3
+ GITHUB_DOMAIN=
4
+ GITHUB_API_ENDPOINT=
data/.gitignore ADDED
@@ -0,0 +1,16 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
13
+
14
+ .env
15
+ /repos/*
16
+ !/repos/.gitkeep
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format progress
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.2
5
+ - 2.5.0
6
+ bundler_args: --without production
7
+ cache: bundler
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at kimromi4@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 kimromi
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,29 @@
1
+ # Ruboty::Packman
2
+
3
+ [![Build Status](https://travis-ci.org/kimromi/ruboty-packman.svg?branch=master)](https://travis-ci.org/kimromi/ruboty-packman)
4
+
5
+ library update tool in package manager for Ruboty.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'ruboty-packman'
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ TODO: Write usage instructions here
18
+
19
+ ## Contributing
20
+
21
+ Bug reports and pull requests are welcome on GitHub at https://github.com/kimromi/ruboty-packman. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
22
+
23
+ ## License
24
+
25
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
26
+
27
+ ## Code of Conduct
28
+
29
+ Everyone interacting in the Ruboty::Packman project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/kimromi/ruboty-packman/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ruboty/packman"
5
+
6
+ require "dotenv"
7
+ Dotenv.load
8
+
9
+ require "ruboty"
10
+ Ruboty::CommandBuilder.new(ARGV).build.call
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,33 @@
1
+ require "ruboty/packman/actions/packman"
2
+
3
+ module Ruboty
4
+ module Handlers
5
+ class Packman < Base
6
+ on(
7
+ /packman add (?<organization>.+) (?<repository>.+)\z/,
8
+ name: 'add',
9
+ description: '[packman] add repository'
10
+ )
11
+
12
+ on(
13
+ /packman pull-request (?<organization>.+) (?<repository>.+)\z/,
14
+ name: 'pull_request',
15
+ description: '[packman] library update'
16
+ )
17
+
18
+ def add(message)
19
+ action_class(message).add
20
+ end
21
+
22
+ def pull_request(message)
23
+ action_class(message).pull_request
24
+ end
25
+
26
+ private
27
+
28
+ def action_class(message)
29
+ Ruboty::Packman::Actions::Packman.new(message)
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,46 @@
1
+ module Ruboty
2
+ module Packman
3
+ module Actions
4
+ class Packman < Ruboty::Actions::Base
5
+ NAMESPACE = 'packman'
6
+
7
+ def add
8
+ if repositories.include?(repo.full_name)
9
+ message.reply("already added. #{repo.full_name}")
10
+ return
11
+ end
12
+
13
+ repo.sync!
14
+
15
+ repositories << repo.full_name
16
+ message.reply("added! #{repo.full_name}")
17
+ end
18
+
19
+ def pull_request
20
+ unless repositories.include?(repo.full_name)
21
+ message.reply("invalid. #{repo.full_name}")
22
+ return
23
+ end
24
+
25
+ repo.sync!
26
+ repo.bundle_update!
27
+ repo.push!
28
+ repo.pull_request!
29
+
30
+ message.reply("pull-requested! #{repo.full_name}")
31
+ end
32
+
33
+ private
34
+
35
+ def repositories
36
+ message.robot.brain.data[NAMESPACE] ||= []
37
+ end
38
+
39
+ def repo
40
+ @repo ||= Ruboty::Packman::GithubRepository.new(message[:organization], message[:repository])
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+
@@ -0,0 +1,87 @@
1
+ require 'git'
2
+ require 'open3'
3
+ require 'shellwords'
4
+ require 'octokit'
5
+
6
+ module Ruboty
7
+ module Packman
8
+ class GithubRepository
9
+ attr_reader :org, :name
10
+
11
+ def initialize(org, name)
12
+ @org = org
13
+ @name = name
14
+ end
15
+
16
+ def full_name
17
+ "#{org}/#{name}"
18
+ end
19
+
20
+ def sync_directory
21
+ "#{repos_dir}/#{full_name}"
22
+ end
23
+
24
+ def sync!
25
+ if cloned?
26
+ git = Git.open(sync_directory)
27
+ git.checkout('master')
28
+ git.pull
29
+ else
30
+ Git.clone("https://#{token}:x-oauth-basic@#{domain}/#{full_name}", sync_directory)
31
+ end
32
+ end
33
+
34
+ def bundle_update!
35
+ out, err, status = Bundler.with_clean_env { Open3.capture3("cd #{sync_directory.shellescape} && bundle update") }
36
+ end
37
+
38
+ def push!
39
+ git = Git.open(sync_directory)
40
+ git.branch(branch_name).checkout
41
+ git.commit_all('bundle update')
42
+ git.push('origin', branch_name)
43
+ end
44
+
45
+ def pull_request!
46
+ Octokit::Client.new(api_endpoint: api_endpoint, access_token: token).create_pull_request(
47
+ full_name,
48
+ 'master',
49
+ branch_name,
50
+ "bundle update #{Time.now.strftime('%Y-%m-%d %H:%M:%S')}",
51
+ 'Pull requested from [packman](https://github.com/kimromi/ruboty-packman).'
52
+ )
53
+ rescue Octokit::UnprocessableEntity => e
54
+ puts e
55
+ end
56
+
57
+ private
58
+
59
+ def repos_dir
60
+ ENV['PACKMAN_REPOS_DIR'] || File.realpath("#{__dir__}/../../../repos")
61
+ end
62
+
63
+ def token
64
+ ENV['GITHUB_TOKEN']
65
+ end
66
+
67
+ def domain
68
+ ENV['GITHUB_DOMAIN'] || 'github.com'
69
+ end
70
+
71
+ def api_endpoint
72
+ ENV['GITHUB_API_ENDPOINT'] || 'https://api.github.com'
73
+ end
74
+
75
+ def cloned?
76
+ Dir.exist?(sync_directory) && Git.open(sync_directory)
77
+ rescue ArgumentError
78
+ FileUtils.rm_rf(sync_directory)
79
+ false
80
+ end
81
+
82
+ def branch_name
83
+ @branch_name ||= "bundle-update-#{Time.now.strftime('%Y%m%d%H%M%S')}"
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,5 @@
1
+ module Ruboty
2
+ module Packman
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,10 @@
1
+ require "ruboty"
2
+ require "ruboty/packman/version"
3
+ require "ruboty/handlers/packman"
4
+ require "ruboty/packman/actions/packman"
5
+ require "ruboty/packman/github_repository"
6
+
7
+ module Ruboty
8
+ module Packman
9
+ end
10
+ end
data/repos/.gitkeep ADDED
File without changes
@@ -0,0 +1,31 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "ruboty/packman/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "ruboty-packman"
7
+ spec.version = Ruboty::Packman::VERSION
8
+ spec.authors = ["kimromi"]
9
+ spec.email = ["kimromi4@gmail.com"]
10
+
11
+ spec.summary = %q{library update tool in package manager for Ruboty.}
12
+ spec.description = %q{library update tool in package manager for Ruboty.}
13
+ spec.homepage = "https://github.com/kimromi/ruboty-packman"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency "ruboty"
24
+ spec.add_dependency "git"
25
+ spec.add_dependency "octokit"
26
+ spec.add_development_dependency "bundler", "~> 1.16"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "pry"
29
+ spec.add_development_dependency "dotenv"
30
+ spec.add_development_dependency "rspec"
31
+ end
metadata ADDED
@@ -0,0 +1,174 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruboty-packman
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - kimromi
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-02-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ruboty
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: git
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: octokit
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.16'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.16'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: dotenv
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: library update tool in package manager for Ruboty.
126
+ email:
127
+ - kimromi4@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".env.sample"
133
+ - ".gitignore"
134
+ - ".rspec"
135
+ - ".travis.yml"
136
+ - CODE_OF_CONDUCT.md
137
+ - Gemfile
138
+ - LICENSE.txt
139
+ - README.md
140
+ - Rakefile
141
+ - bin/console
142
+ - bin/setup
143
+ - lib/ruboty/handlers/packman.rb
144
+ - lib/ruboty/packman.rb
145
+ - lib/ruboty/packman/actions/packman.rb
146
+ - lib/ruboty/packman/github_repository.rb
147
+ - lib/ruboty/packman/version.rb
148
+ - repos/.gitkeep
149
+ - ruboty-packman.gemspec
150
+ homepage: https://github.com/kimromi/ruboty-packman
151
+ licenses:
152
+ - MIT
153
+ metadata: {}
154
+ post_install_message:
155
+ rdoc_options: []
156
+ require_paths:
157
+ - lib
158
+ required_ruby_version: !ruby/object:Gem::Requirement
159
+ requirements:
160
+ - - ">="
161
+ - !ruby/object:Gem::Version
162
+ version: '0'
163
+ required_rubygems_version: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ requirements: []
169
+ rubyforge_project:
170
+ rubygems_version: 2.7.3
171
+ signing_key:
172
+ specification_version: 4
173
+ summary: library update tool in package manager for Ruboty.
174
+ test_files: []