deploy_log 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: 505e79f62c93e38a1f840405eafeb09f8395d58f4008ccc13a5a5e29897a0809
4
+ data.tar.gz: b9fb74c7829de958cd8f126b88ac89e50c13b5e4591362f0017b00bfbbbcae88
5
+ SHA512:
6
+ metadata.gz: 6eb0bb8d8f2deac5676e329b01ffdda3b07eaa6682f8ed013c73769a3b34ac4e660c4258f5f6fa8d2bc3f4aaa019c2991f3a831da218c701be36bb9be72f073b
7
+ data.tar.gz: 61cd4cce678119e687c2691942e21344b98a830e028df7acf3d7d8bc662c588c01a6b66615c9ac5e818a78ed3bbb9b55de8b8609885bbe48620c199e28f4d1db
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ *.gem
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.0
7
+ before_install: gem install bundler -v 2.0.1
@@ -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 rpriebe@me.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,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in deploy_log.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 TODO: Write your name
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,93 @@
1
+ # DeployLog
2
+
3
+ Get all Github pull requests for a specific timeframe, or search by title/branch name.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'deploy_log'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ > $ bundle
16
+
17
+ Or install it yourself as:
18
+ > $ gem install deploy_log
19
+
20
+ ## Usage
21
+
22
+ First, make sure your Github username and a [personal access token](https://github.com/settings/tokens) are setup as follows:
23
+
24
+ ```bash
25
+ export GITHUB_USER="octocat"
26
+ export GITHUB_TOKEN="someRandomStringHere"
27
+ ```
28
+
29
+ Search in any valid date range.
30
+
31
+ ```bash
32
+ $ deploy_log my/repo --start=2019-06-11 --end=2019-06-12
33
+
34
+ # My PR title (https://github.com/my/repo/pull/1)
35
+ # - Created by octocat
36
+ # - Branch: my_branch
37
+ # - Merged by octocat on 11/6/2019 @ 04:13:35pm
38
+ # - Changes: https://github.com/my/repo/pull/1.diff
39
+ #
40
+ # ============================================================
41
+ # 1 PR(s) merged from 2019-06-11 00:00:00 -0600 to 2019-06-12 00:00:00 -0600
42
+ # ============================================================
43
+ ```
44
+
45
+ Search by PR name.
46
+
47
+ ```bash
48
+ $ deploy_log my/repo --title="My PR title"
49
+
50
+ # My PR title (https://github.com/my/repo/pull/1)
51
+ # - Created by octocat
52
+ # - Branch: my_branch
53
+ # - Merged by octocat on 11/6/2019 @ 04:13:35pm
54
+ # - Changes: https://github.com/my/repo/pull/1.diff
55
+ #
56
+ # ============================================================
57
+ # 1 PR(s) matched
58
+ # ============================================================
59
+ ```
60
+
61
+ Find a PR by branch name.
62
+
63
+ ```bash
64
+ $ deploy_log my/repo --branch="my_branch"
65
+
66
+ # My PR title (https://github.com/my/repo/pull/1)
67
+ # - Created by octocat
68
+ # - Branch: my_branch
69
+ # - Merged by octocat on 11/6/2019 @ 04:13:35pm
70
+ # - Changes: https://github.com/my/repo/pull/1.diff
71
+ #
72
+ # ============================================================
73
+ # 1 PR(s) matched
74
+ # ============================================================
75
+ ```
76
+
77
+ ## Development
78
+
79
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
80
+
81
+ 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`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
82
+
83
+ ## Contributing
84
+
85
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/deploy_log. 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.
86
+
87
+ ## License
88
+
89
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
90
+
91
+ ## Code of Conduct
92
+
93
+ Everyone interacting in the DeployLog project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/deploy_log/blob/master/CODE_OF_CONDUCT.md).
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.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
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 "deploy_log"
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(__FILE__)
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,30 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "deploy_log/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "deploy_log"
7
+ spec.version = DeployLog::VERSION
8
+ spec.authors = ["Ryan Priebe"]
9
+ spec.email = ["rpriebe@me.com"]
10
+
11
+ spec.summary = "Find out what pull requests are merged within a specific timeframe, or search by PR title or branch name"
12
+ spec.description = "That's prety much it"
13
+ spec.homepage = "https://github.com/aapis/deploy_log"
14
+ spec.license = "MIT"
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.bindir = 'exe'
22
+ spec.executables = 'deploy_log'
23
+ spec.require_paths = ['lib']
24
+
25
+ spec.add_development_dependency 'bundler', '~> 2.0'
26
+ spec.add_development_dependency 'rake', '~> 10.0'
27
+ spec.add_runtime_dependency 'notifaction', '~> 0.4.4'
28
+ spec.add_development_dependency 'minitest', '~> 5.0'
29
+ spec.add_runtime_dependency 'octokit', '~> 4.0'
30
+ end
data/exe/deploy_log ADDED
@@ -0,0 +1,39 @@
1
+ #! /usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'notifaction'
5
+ require 'octokit'
6
+ require 'optionparser'
7
+ require 'time'
8
+ require 'deploy_log'
9
+
10
+ start, finish, title, branch = nil
11
+
12
+ OptionParser.new do |opt|
13
+ opt.on('-s', '--start=START', 'Start of date range') do |time|
14
+ start = Time.parse(time)
15
+ end
16
+
17
+ opt.on('-e', '--end=END', 'End of date range') do |time|
18
+ finish = Time.parse(time)
19
+ end
20
+
21
+ opt.on('-t', '--title=TITLE', 'Title of the PR you want') do |ti|
22
+ title = ti
23
+ end
24
+
25
+ opt.on('-b', '--branch=BRANCH', 'Name of the branch you want') do |br|
26
+ branch = br
27
+ end
28
+
29
+ opt.on('-v', '--version', 'Prints version information') do
30
+ puts DeployLog::VERSION
31
+ exit
32
+ end
33
+ end.parse!
34
+
35
+ model = GithubDeploys.new
36
+ model.merged_between(start, finish) if start && finish
37
+ model.pr_title(title) if title
38
+ model.pr_for_branch(branch) if branch
39
+ model.merged_today if title.nil? && branch.nil? && start.nil? && finish.nil?
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ class GithubDeploys
4
+ def initialize
5
+ @github = GithubHelper.new(ARGV.first)
6
+ end
7
+
8
+ def merged_between(start, finish)
9
+ unless start && finish
10
+ Notify.error("Start and end dates (--start= and --end=) are required")
11
+ end
12
+
13
+ @github.pulls_in_timeframe(start, finish)
14
+ end
15
+
16
+ def merged_today
17
+ start = Date.today.to_time # 12:00AM this morning
18
+ finish = Date.today.to_time + (24 * 60 * 60) - 1 # 11:59PM tonight
19
+
20
+ @github.pulls_in_timeframe(start, finish)
21
+ end
22
+
23
+ def merged_on(start)
24
+ unless start
25
+ Notify.error("Start date (--start=) is required")
26
+ end
27
+
28
+ finish = start + 24 * 60 * 60 - 1
29
+
30
+ @github.pulls_in_timeframe(start, finish)
31
+ end
32
+
33
+ def pr_title(title)
34
+ @github.search_pulls_by(title, :title)
35
+ end
36
+
37
+ def pr_for_branch(branch)
38
+ @github.search_pulls_by(branch, :ref)
39
+ end
40
+ end
@@ -0,0 +1,105 @@
1
+ # frozen_string_literal: true
2
+
3
+
4
+ class GithubHelper
5
+ def initialize(user_repo)
6
+ @client = Octokit::Client.new(login: ENV['GITHUB_USER'], password: ENV['GITHUB_TOKEN'])
7
+ @repo_location = user_repo
8
+ end
9
+
10
+ def pulls_in_timeframe(date_start = nil, date_end = nil)
11
+ @client.auto_paginate = true
12
+ list = @client.pull_requests(@repo_location,
13
+ state: :closed,
14
+ per_page: 500,
15
+ sort: 'long-running'
16
+ )
17
+
18
+ pr_format_str = "%s (%s)\n - Created by %s\n - Branch: %s\n - Merged by %s on %s\n - Changes: %s\n\n"
19
+ prs_covered = 0
20
+
21
+ File.open('/tmp/github-deploys.log', 'w+') do |f|
22
+ list.each do |pr|
23
+ next unless (date_start..date_end).cover? pr.merged_at
24
+
25
+ prs_covered += 1
26
+
27
+ f.write(
28
+ sprintf(
29
+ pr_format_str,
30
+ pr.title,
31
+ pr.html_url,
32
+ pr.user.login,
33
+ pr.head.ref,
34
+ user_who_merged(pr.number),
35
+ formatted_time(pr.merged_at),
36
+ pr.diff_url
37
+ )
38
+ )
39
+ end
40
+
41
+ f.write("============================================================\n#{prs_covered} PR(s) merged from #{date_start} to #{date_end}\n============================================================\n")
42
+ end
43
+
44
+ return Notify.warning("No pull requests have been merged in the requested date range (#{date_start} - #{date_end})") if prs_covered.zero?
45
+
46
+ system('cat /tmp/github-deploys.log')
47
+ end
48
+
49
+ def search_pulls_by(value, field = :title)
50
+ list = @client.pull_requests(@repo_location,
51
+ :state => :all,
52
+ :per_page => 100
53
+ )
54
+ pr_format_str = "%s (%s)\n - Created by %s\n - Branch: %s\n - Changes: %s\n\n"
55
+ prs_covered = 0
56
+
57
+ File.open('/tmp/github-deploys.log', 'w+') do |f|
58
+ list.each do |pr|
59
+ next unless nested_hash_value(pr, field).match?(/#{value}\b/)
60
+
61
+ prs_covered += 1
62
+
63
+ f.write(
64
+ sprintf(
65
+ pr_format_str,
66
+ pr.title,
67
+ pr.html_url,
68
+ pr.user.login,
69
+ pr.head.ref,
70
+ pr.diff_url
71
+ )
72
+ )
73
+ end
74
+
75
+ f.write("============================================================\n#{prs_covered} PR(s) matched\n============================================================\n")
76
+ end
77
+
78
+ return Notify.warning("No pull requests match the requested term (#{value})") if prs_covered.zero?
79
+
80
+ system('cat /tmp/github-deploys.log')
81
+ end
82
+
83
+ private
84
+
85
+ def user_who_merged(pr_number)
86
+ pr = @client.pull_request(@repo_location, pr_number)
87
+ pr.merged_by.login
88
+ end
89
+
90
+ def formatted_time(time, correct_utc = false)
91
+ time = Time.now if time.nil?
92
+ time = time.localtime if correct_utc
93
+ time.strftime('%e/%-m/%Y @ %I:%M:%S%P')
94
+ end
95
+
96
+ def nested_hash_value(obj, key)
97
+ if obj.respond_to?(:key?) && obj.key?(key)
98
+ obj[key]
99
+ elsif obj.respond_to?(:each)
100
+ r = nil
101
+ obj.find{ |*a| r=nested_hash_value(a.last,key) }
102
+ r
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,3 @@
1
+ module DeployLog
2
+ VERSION = "0.1.0"
3
+ end
data/lib/deploy_log.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'deploy_log/version'
2
+ require 'deploy_log/github_helper'
3
+ require 'deploy_log/github_deploys'
4
+
5
+ module DeployLog
6
+ class Error < StandardError; end
7
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: deploy_log
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ryan Priebe
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-06-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: notifaction
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.4.4
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.4.4
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: octokit
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '4.0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '4.0'
83
+ description: That's prety much it
84
+ email:
85
+ - rpriebe@me.com
86
+ executables:
87
+ - deploy_log
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".travis.yml"
93
+ - CODE_OF_CONDUCT.md
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - bin/console
99
+ - bin/setup
100
+ - deploy_log.gemspec
101
+ - exe/deploy_log
102
+ - lib/deploy_log.rb
103
+ - lib/deploy_log/github_deploys.rb
104
+ - lib/deploy_log/github_helper.rb
105
+ - lib/deploy_log/version.rb
106
+ homepage: https://github.com/aapis/deploy_log
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubygems_version: 3.0.1
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: Find out what pull requests are merged within a specific timeframe, or search
129
+ by PR title or branch name
130
+ test_files: []