Skip to content

Commit

Permalink
Also write out json
Browse files Browse the repository at this point in the history
  • Loading branch information
Firefishy committed Dec 8, 2023
1 parent c6f1a08 commit b471524
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 19 deletions.
10 changes: 10 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -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
11 changes: 8 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
source "https://rubygems.org"
# frozen_string_literal: true

gem "git", "~> 1.18.0"
gem "octokit", "~> 8.0.0"
source 'https://rubygems.org'

gem 'git', '~> 1.18.0'
gem 'json', '~> 2.7'
gem 'octokit', '~> 8.0.0'

gem 'rubocop', '~> 1.58', groups: 'development'
28 changes: 28 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -12,23 +13,50 @@ 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
x86_64-linux

DEPENDENCIES
git (~> 1.18.0)
json (~> 2.7)
octokit (~> 8.0.0)
rubocop (~> 1.58)

BUNDLED WITH
2.4.21
43 changes: 27 additions & 16 deletions bin/update-issues
100644 → 100755
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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}"
Expand All @@ -37,37 +40,45 @@ end

git = Git.open(gitdir)

git.config("user.name", "Tile-Attribution Updater")
git.config("user.email", "[email protected]")
git.config('user.name', 'Tile-Attribution Updater')
git.config('user.email', '[email protected]')

# 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

0 comments on commit b471524

Please sign in to comment.