From b4715244b355f2fd2822a900b371982cfe03317c Mon Sep 17 00:00:00 2001 From: Grant Slater Date: Fri, 8 Dec 2023 13:57:39 +0000 Subject: [PATCH] Also write out json --- .rubocop.yml | 10 ++++++++++ Gemfile | 11 ++++++++--- Gemfile.lock | 28 ++++++++++++++++++++++++++++ bin/update-issues | 43 +++++++++++++++++++++++++++---------------- 4 files changed, 73 insertions(+), 19 deletions(-) create mode 100644 .rubocop.yml mode change 100644 => 100755 bin/update-issues diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..cc4712a --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,10 @@ +# The behavior of RuboCop can be controlled via the .rubocop.yml +# configuration file. It makes it possible to enable/disable +# certain cops (checks) and to alter their behavior if they accept +# any parameters. The file can be placed either in your home +# directory or in some project directory. +# +# RuboCop will start looking for the configuration file in the directory +# where the inspected file is and continue its way up to the root directory. +# +# See https://docs.rubocop.org/rubocop/configuration diff --git a/Gemfile b/Gemfile index ccda660..28ae63f 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,9 @@ -source "https://rubygems.org" +# frozen_string_literal: true -gem "git", "~> 1.18.0" -gem "octokit", "~> 8.0.0" \ No newline at end of file +source 'https://rubygems.org' + +gem 'git', '~> 1.18.0' +gem 'json', '~> 2.7' +gem 'octokit', '~> 8.0.0' + +gem 'rubocop', '~> 1.58', groups: 'development' diff --git a/Gemfile.lock b/Gemfile.lock index b5ddb35..da0a7b3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -3,6 +3,7 @@ GEM specs: addressable (2.8.5) public_suffix (>= 2.0.2, < 6.0) + ast (2.4.2) base64 (0.1.1) faraday (2.7.11) base64 @@ -12,15 +13,40 @@ GEM git (1.18.0) addressable (~> 2.8) rchardet (~> 1.8) + json (2.7.1) + language_server-protocol (3.17.0.3) octokit (8.0.0) faraday (>= 1, < 3) sawyer (~> 0.9) + parallel (1.23.0) + parser (3.2.2.4) + ast (~> 2.4.1) + racc public_suffix (5.0.3) + racc (1.7.3) + rainbow (3.1.1) rchardet (1.8.0) + regexp_parser (2.8.3) + rexml (3.2.6) + rubocop (1.58.0) + json (~> 2.3) + language_server-protocol (>= 3.17.0) + parallel (~> 1.10) + parser (>= 3.2.2.4) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.30.0, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.30.0) + parser (>= 3.2.1.0) + ruby-progressbar (1.13.0) ruby2_keywords (0.0.5) sawyer (0.9.2) addressable (>= 2.3.5) faraday (>= 0.17.3, < 3) + unicode-display_width (2.5.0) PLATFORMS arm64-darwin-23 @@ -28,7 +54,9 @@ PLATFORMS DEPENDENCIES git (~> 1.18.0) + json (~> 2.7) octokit (~> 8.0.0) + rubocop (~> 1.58) BUNDLED WITH 2.4.21 diff --git a/bin/update-issues b/bin/update-issues old mode 100644 new mode 100755 index 2341bde..21f93d0 --- a/bin/update-issues +++ b/bin/update-issues @@ -1,10 +1,13 @@ #!/usr/bin/ruby +# frozen_string_literal: true -require "git" -require "octokit" -require "csv" +require 'git' +require 'octokit' +require 'csv' +require 'json' -TILE_ATTRIBUTION_FILE = "tile-attribution.csv" +TILE_ATTRIBUTION_FILE = 'tile-attribution.csv' +TILE_ATTRIBUTION_JSON = 'tile-attribution.json' gitdir = Dir.pwd def log_message(message) @@ -23,10 +26,10 @@ def generate_commit_message(git) last_change = change_lines.last if last_change.start_with?('+') - action = "Added" + action = 'Added' content = last_change[1..].strip.split(',')[0] # Assuming the first CSV column contains the desired content elsif last_change.start_with?('-') - action = "Removed" + action = 'Removed' content = last_change[1..].strip.split(',')[0] else return "Updated #{TILE_ATTRIBUTION_FILE}" @@ -37,37 +40,45 @@ end git = Git.open(gitdir) -git.config("user.name", "Tile-Attribution Updater") -git.config("user.email", "admins@openstreetmap.org") +git.config('user.name', 'Tile-Attribution Updater') +git.config('user.email', 'admins@openstreetmap.org') # GitHub repository in the format "owner/repo" -repo = ENV["GITHUB_REPOSITORY"] -branch = ENV["GITHUB_REF_NAME"] +repo = ENV['GITHUB_REPOSITORY'] +branch = ENV['GITHUB_REF_NAME'] # Pull all changes log_message("Pulling changes from #{branch}...") -git.fetch("origin") +git.fetch('origin') git.reset_hard("origin/#{branch}") -client = Octokit::Client.new(bearer_token: ENV["GITHUB_TOKEN"]) +client = Octokit::Client.new(bearer_token: ENV['GITHUB_TOKEN']) client.auto_paginate = true -issues = client.issues(repo, state: "open", labels: "accepted") +issues = client.issues(repo, state: 'open', labels: 'accepted') -CSV.open(TILE_ATTRIBUTION_FILE, "w") do |csv| - csv << ["title", "link", "date"] +CSV.open(TILE_ATTRIBUTION_FILE, 'w') do |csv| + csv << %w[title link date] issues.each do |issue| csv << [issue.title, issue.html_url, issue.created_at] end end +File.open(JSON_OUTPUT_FILE, 'w') do |file| + issue_data = issues.map { |issue| [issue[:title], issue[:html_url]] }.to_h + file.write(JSON.pretty_generate(issue_data)) +end + if git.status.changed.include?(TILE_ATTRIBUTION_FILE) log_message("Add #{TILE_ATTRIBUTION_FILE} to git") git.add(TILE_ATTRIBUTION_FILE) + log_message("Add #{TILE_ATTRIBUTION_JSON} to git") + git.add(TILE_ATTRIBUTION_JSON) + commit_message = generate_commit_message(git) log_message("Commit changes to #{branch} with message: '#{commit_message}'") git.commit(commit_message) log_message("Push branch #{branch}...") - git.push("origin", branch) + git.push('origin', branch) end