diff --git a/README.md b/README.md index d298e01..68e92df 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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). diff --git a/bin/commands/releases.rb b/bin/commands/releases.rb new file mode 100644 index 0000000..4ffc857 --- /dev/null +++ b/bin/commands/releases.rb @@ -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 diff --git a/lib/github/release.rb b/lib/github/release.rb new file mode 100644 index 0000000..da387a9 --- /dev/null +++ b/lib/github/release.rb @@ -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 diff --git a/lib/github/repo.rb b/lib/github/repo.rb index 04917c2..1156d8a 100644 --- a/lib/github/repo.rb +++ b/lib/github/repo.rb @@ -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 diff --git a/lib/tools.rb b/lib/tools.rb index 80fe561..6420ab6 100644 --- a/lib/tools.rb +++ b/lib/tools.rb @@ -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'