Skip to content

Commit b136826

Browse files
authored
v1.0.0 (#29)
New features: * Add a CLI option --config for config filename * Add support for GitHub Enterprise repos Maintenance: * Use slim linter * Update docs
1 parent b759f9c commit b136826

File tree

9 files changed

+129
-22
lines changed

9 files changed

+129
-22
lines changed

.github/workflows/linter.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ jobs:
4242
# Run Linter against code base #
4343
################################
4444
- name: Lint Code Base
45-
uses: github/super-linter@v4
45+
uses: github/super-linter/slim@v4
4646
env:
47-
VALIDATE_ALL_CODEBASE: false
4847
DEFAULT_BRANCH: main
48+
VALIDATE_ALL_CODEBASE: false
49+
VALIDATE_GITLEAKS: false

Gemfile.lock

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
whatsup_github (0.5.0)
4+
whatsup_github (1.0.0)
55
netrc (~> 0.11)
66
octokit (~> 6.0)
77
thor (~> 1.2)
@@ -91,6 +91,7 @@ GEM
9191
thor (1.2.1)
9292

9393
PLATFORMS
94+
arm64-darwin-22
9495
ruby
9596

9697
DEPENDENCIES

README.md

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,22 @@ One pull request sources one data entity.
99
All filtering parameters are set in a configuration file, except dates.
1010
_Since_ date is set as a CLI argument and the _till_ date is always the moment when the command is run.
1111

12+
## CLI
13+
14+
```console
15+
Commands:
16+
whatsup_github help [COMMAND] # Describe available commands or one specific command
17+
whatsup_github since DATE # Filters pull requests since the specified date till now. Default: last 7 days.
18+
whatsup_github version # Current version of the gem
19+
20+
Usage:
21+
whatsup_github since DATE
22+
23+
Options:
24+
[--config=CONFIG] # Relative path to the configuration file.
25+
# Default: .whatsup.yml
26+
```
27+
1228
## What's generated
1329

1430
A resulting YAML file `tmp/whats-new.yml` is generated from GitHub data.
@@ -38,7 +54,7 @@ Set as a list of `labels` in `.whatsup.yml`. There are two types of labels in co
3854

3955
### `versions`
4056

41-
Any GitHub label that starts from a digit followed by a period like in regex `\d\.`.
57+
Any GitHub label that starts from a digit followed by a period like in regular expression `\d\.`.
4258
Examples: `2.3.x`, `1.0.3-msi`, `2.x`
4359

4460
### `date`
@@ -59,7 +75,7 @@ Merge commit SHA of the pull request.
5975

6076
### `membership`
6177

62-
Memebership of the contributor in a configured organization.
78+
Membership of the contributor in a configured organization.
6379

6480
### `labels`
6581

@@ -91,7 +107,13 @@ bundle
91107

92108
## Configuration
93109

94-
The configuration file [`.whatsup.yml`](lib/template/.whatsup.yml) will be created automatically after first run unless it's already there.
110+
The default configuration file [`.whatsup.yml`](lib/template/.whatsup.yml) will be created automatically after first run unless it's already there.
111+
112+
To use non-default location or name of the file, use the --config option. Example:
113+
114+
```shell
115+
whatsup_github since 'apr 9' --config 'configs/whatsup_bp.yml'
116+
```
95117

96118
## Authentication
97119

@@ -109,8 +131,20 @@ Example:
109131

110132
```config
111133
machine api.github.com
112-
login dshevtsov
134+
login mypubliclogin
135+
password y9o6YvEoa7IukRWUFdnkpuxNjJ3uwiDQp4zkAdU0
136+
```
137+
138+
Example with GitHub Enterprise:
139+
140+
```config
141+
machine api.github.com
142+
login mypubliclogin
113143
password y9o6YvEoa7IukRWUFdnkpuxNjJ3uwiDQp4zkAdU0
144+
145+
machine git.enterprise.example.com
146+
login myenterpriselogin
147+
password GtH7yhvEoa7Iuksdo&TFuxNjJ3uwiDQhjbiu8&yhJhG
114148
```
115149

116150
### With an environment variable
@@ -202,7 +236,7 @@ The tests use the root `.whatsup.yml` file to read configuration.
202236

203237
## Contributing
204238

205-
Bug reports and pull requests are welcome on GitHub at https://github.com/dshevtsov/whatsup_github. 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.
239+
Bug reports and pull requests are welcome. 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.
206240

207241
## License
208242

lib/template/.whatsup.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
# Parameters for a GitHub search query
22
base_branch: master
33

4+
# Set hostname to read repos at GitHub Enterprise
5+
# enterprise: <hostname>
6+
47
# The list of repositories to scan for pull requests
8+
# For repos at GitHub Enterprise, add a prefix 'enterprise:'. Example: enterprise:magento/devdocs.
59
repos:
610
- magento/devdocs
711

lib/whatsup_github/cli.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ module WhatsupGithub
77
# CLI options
88
class CLI < Thor
99
desc 'since DATE', 'Filters pull requests since the specified date till now. Default: last 7 days.'
10+
option :config,
11+
desc: 'Relative path to the configuration file.',
12+
default: '.whatsup.yml'
1013
def since(date = Date.today - 7)
14+
WhatsupGithub::Config.filename = options[:config]
1115
runner = WhatsupGithub::Runner.new(Date.parse(date.to_s))
1216
runner.run
1317
end

lib/whatsup_github/config_reader.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,14 @@ class Config
1111

1212
include Singleton
1313

14+
@@filename = ''
15+
16+
def self.filename=(filename)
17+
@@filename = filename
18+
end
19+
1420
def initialize
15-
@file = '.whatsup.yml'
21+
@file = @@filename
1622
@config = {}
1723
end
1824

@@ -64,6 +70,10 @@ def membership
6470
def magic_word
6571
read['magic_word']
6672
end
73+
74+
def enterprise
75+
read['enterprise']
76+
end
6777
end
6878
end
6979

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# frozen_string_literal: true
2+
3+
require 'singleton'
4+
5+
# Client authorization
6+
module WhatsupGithub
7+
# Create a singleton object for EnterpriseClient.
8+
# Authorize with a GitHub Enterprise token from $WHATSUP_ENTERPRISE_ACCESS_TOKEN if available
9+
# Otherwise, use credentials from ~/.netrc
10+
class EnterpriseClient < Client
11+
include Singleton
12+
13+
WHATSUP_ENTERPRISE_ACCESS_TOKEN = ENV['WHATSUP_ENTERPRISE_ACCESS_TOKEN']
14+
private_constant :WHATSUP_ENTERPRISE_ACCESS_TOKEN
15+
16+
@@hostname = ''
17+
18+
def self.host=(hostname)
19+
abort "ERROR: Set value for 'enterprise' in the whatsup_github configuration" if hostname.nil?
20+
@@hostname = hostname
21+
end
22+
23+
def initialize
24+
Octokit.configure do |c|
25+
c.api_endpoint = "https://#{@@hostname}/api/v3/"
26+
end
27+
@client =
28+
if WHATSUP_ENTERPRISE_ACCESS_TOKEN
29+
Octokit::Client.new(access_token: WHATSUP_ENTERPRISE_ACCESS_TOKEN)
30+
elsif File.exist? "#{ENV['HOME']}/.netrc"
31+
Octokit::Client.new(netrc: true)
32+
end
33+
end
34+
end
35+
end

lib/whatsup_github/pulls.rb

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require 'octokit'
44
require_relative 'config_reader'
55
require_relative 'client'
6+
require_relative 'enterprise_client'
67

78
module WhatsupGithub
89
# Gets issues found on GitHub by query
@@ -24,10 +25,6 @@ def data
2425

2526
private
2627

27-
# def access_token
28-
# credentials.dig 'github_token'
29-
# end
30-
3128
def configuration
3229
Config.instance
3330
end
@@ -48,25 +45,46 @@ def base_branch
4845
configuration.base_branch
4946
end
5047

51-
# Authorize with a GitHub token from $WHATSUP_GITHUB_ACCESS_TOKEN if available
52-
# Otherwise, use credentials from ~/.netrc
53-
# Otherwise, continue as a Guest
5448
def client
5549
Client.instance
5650
end
5751

52+
def enterprise_client
53+
WhatsupGithub::EnterpriseClient.host = configuration.enterprise
54+
EnterpriseClient.instance
55+
end
56+
5857
def search_issues(label)
5958
auto_paginate
60-
query = "repo:#{repo} label:\"#{label}\" merged:>=#{since} base:#{base_branch} is:pull-request"
61-
puts "Searching on GitHub by query #{query}"
62-
client.search_issues(query)
59+
call_query query(label)
6360
end
6461

6562
def search_issues_with_magic_word(label)
6663
auto_paginate
67-
query = "repo:#{repo} label:\"#{label}\" merged:>=#{since} base:#{base_branch} \"#{magic_word}\" in:body is:pull-request"
64+
call_query query_with_magic_word(label)
65+
end
66+
67+
def call_query(query)
6868
puts "Searching on GitHub by query #{query}"
69-
client.search_issues(query)
69+
if repo.start_with? 'enterprise:'
70+
enterprise_client.search_issues(
71+
enterprise_query(query)
72+
)
73+
else
74+
client.search_issues(query)
75+
end
76+
end
77+
78+
def enterprise_query(query)
79+
query.gsub('enterprise:', '')
80+
end
81+
82+
def query(label)
83+
"repo:#{repo} label:\"#{label}\" merged:>=#{since} base:#{base_branch} is:pull-request"
84+
end
85+
86+
def query_with_magic_word(label)
87+
query(label) + " \"#{magic_word}\" in:body"
7088
end
7189

7290
def auto_paginate

lib/whatsup_github/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module WhatsupGithub
4-
VERSION = '0.5.0'
4+
VERSION = '1.0.0'
55
end

0 commit comments

Comments
 (0)