Skip to content

Commit

Permalink
Show latest releases. (#94)
Browse files Browse the repository at this point in the history
Signed-off-by: dblock <[email protected]>
  • Loading branch information
dblock authored Oct 3, 2024
1 parent 6417a7e commit 2669380
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 0 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
- [Issues](#issues)
- [Member Bios](#member-bios)
- [DCO Signers](#dco-signers)
- [Releases](#releases)
- [Latest Releases](#latest-releases)
- [Contributing](#contributing)
- [Code of Conduct](#code-of-conduct)
- [Security](#security)
Expand Down Expand Up @@ -351,6 +353,22 @@ Shows name and email address from all contributors that have signed a developer
./bin/project contributors dco-signers --from=2022-01-01 --to=2022-01-31 --org=opensearch-project --repo=OpenSearch
```

### Releases

#### Latest Releases

Get if the latest release was last week.

```
./bin/project releases latest
```

Show if the latest release was in 2024.

```
./bin/project releases latest --from=2024-01-01 --to=2024-12-31
```

## Contributing

See [how to contribute to this project](CONTRIBUTING.md).
Expand Down
34 changes: 34 additions & 0 deletions bin/commands/releases.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# frozen_string_literal: true

module Bin
class Commands
desc 'Releases.'
command 'releases' do |g|
g.flag %i[o org], desc: 'Name of the GitHub organization.', default_value: 'opensearch-project'
g.flag %i[repo], multiple: true, desc: 'Search a specific repo within the org.'
g.flag %i[from], desc: 'Start at.', default_value: Date.today.beginning_of_week.last_week
g.flag %i[to], desc: 'End at.', default_value: Date.today.beginning_of_week - 1

g.desc 'Display releases last week.'
g.command 'latest' do |c|
c.action do |_global_options, options, _args|
repos = if options[:repo]&.any?
GitHub::Repos.new(options[:repo])
else
GitHub::Organization.new(options.merge(org: options['org'] || 'opensearch-project')).repos
end
from = Chronic.parse(options[:from]).to_date if options[:from]
to = Chronic.parse(options[:to]).to_date if options[:to]
repos.sort_by(&:name).each do |repo|
release = repo.latest_release
next unless release
next if from && release.created_at < from
next if to && release.created_at > to

puts "#{repo.name}: #{release}"
end
end
end
end
end
end
12 changes: 12 additions & 0 deletions lib/github/release.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

module GitHub
class Release < Item
def to_s
[
"#{name}, created #{DOTIW::Methods.distance_of_time_in_words(created_at, Time.now, highest_measures: 1)} ago",
" #{html_url}"
].join("\n")
end
end
end
10 changes: 10 additions & 0 deletions lib/github/repo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,15 @@ def table_cell(content, _alignment)
nil
end
end

def releases
@releases ||= GitHub::Release.wrap($github.releases(full_name))
end

def latest_release
@latest_release ||= GitHub::Release.new($github.latest_release(full_name))
rescue Octokit::NotFound
nil
end
end
end
1 change: 1 addition & 0 deletions lib/tools.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
require_relative 'github/searchable'
require_relative 'github/data'
require_relative 'github/organization'
require_relative 'github/release'
require_relative 'github/repo'
require_relative 'github/repos'
require_relative 'github/pull_requests'
Expand Down

0 comments on commit 2669380

Please sign in to comment.