From 24a9a78e45f2f05481678a7bdd7b1da3553f43c0 Mon Sep 17 00:00:00 2001 From: Grant Slater Date: Wed, 1 Nov 2023 12:06:46 +0000 Subject: [PATCH] Add automation code --- .editorconfig | 11 +++++++++ .github/dependabot.yml | 10 ++++++++ .github/workflows/update-issues.yml | 27 ++++++++++++++++++++++ .ruby-version | 1 + Gemfile | 4 ++++ Gemfile.lock | 33 ++++++++++++++++++++++++++ bin/update-issues | 36 +++++++++++++++++++++++++++++ 7 files changed, 122 insertions(+) create mode 100644 .editorconfig create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/update-issues.yml create mode 100644 .ruby-version create mode 100644 Gemfile create mode 100644 Gemfile.lock create mode 100644 bin/update-issues diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..c0d0101 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,11 @@ +# EditorConfig is awesome: https://EditorConfig.org + +root = true + +[*] +charset = utf-8 +indent_style = space +trim_trailing_whitespace = true +insert_final_newline = true +end_of_line = lf +indent_size = 2 diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..b599fe4 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,10 @@ +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "daily" + - package-ecosystem: "bundler" + directory: "/" + schedule: + interval: "daily" diff --git a/.github/workflows/update-issues.yml b/.github/workflows/update-issues.yml new file mode 100644 index 0000000..85e2146 --- /dev/null +++ b/.github/workflows/update-issues.yml @@ -0,0 +1,27 @@ +name: Update Issues + +on: + issues: + types: [opened, reopened, closed, labeled, unlabeled] + workflow_dispatch: + +permissions: + contents: write + issues: read + +jobs: + updater: + name: Update Issues + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v4 + - name: Setup ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ruby + bundler-cache: true + - name: Run updater + run: bundle exec ruby bin/update-issues + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..be94e6f --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +3.2.2 diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..ccda660 --- /dev/null +++ b/Gemfile @@ -0,0 +1,4 @@ +source "https://rubygems.org" + +gem "git", "~> 1.18.0" +gem "octokit", "~> 8.0.0" \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..c942b99 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,33 @@ +GEM + remote: https://rubygems.org/ + specs: + addressable (2.8.5) + public_suffix (>= 2.0.2, < 6.0) + base64 (0.1.1) + faraday (2.7.11) + base64 + faraday-net_http (>= 2.0, < 3.1) + ruby2_keywords (>= 0.0.4) + faraday-net_http (3.0.2) + git (1.18.0) + addressable (~> 2.8) + rchardet (~> 1.8) + octokit (8.0.0) + faraday (>= 1, < 3) + sawyer (~> 0.9) + public_suffix (5.0.3) + rchardet (1.8.0) + ruby2_keywords (0.0.5) + sawyer (0.9.2) + addressable (>= 2.3.5) + faraday (>= 0.17.3, < 3) + +PLATFORMS + arm64-darwin-23 + +DEPENDENCIES + git (~> 1.18.0) + octokit (~> 8.0.0) + +BUNDLED WITH + 2.4.21 diff --git a/bin/update-issues b/bin/update-issues new file mode 100644 index 0000000..211870d --- /dev/null +++ b/bin/update-issues @@ -0,0 +1,36 @@ +#!/usr/bin/ruby + +require "git" +require "octokit" +require "csv" + +gitdir = Dir.pwd + +git = Git.open(gitdir) + +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"] + +client = Octokit::Client.new(:bearer_token => ENV["GITHUB_TOKEN"]) +client.auto_paginate = true +issues = client.issues(repo, state: "open", labels: "accepted") + +CSV.open("tile-attribution.csv", "w") do |csv| + csv << ["title", "number", "date"] + issues.each do |issue| + csv << [issue.title, issue.number, issue.closed_at] + end +end + +puts "Add tile-attribution.csv to git" +git.add("tile-attribution.csv") + +puts "Commit changes to #{branch}..." +git.commit("Update tile-attribution.csv") + +puts "Push branch #{branch}..." +git.push("origin", branch) \ No newline at end of file