-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add recent blog posts to the organisation README
We fetch from our main RSS feed every day at 11:00 UTC, then update the "blog" section in the README, which is marked using a comment. It then commits and pushes the changes. This is based on some prior work here: https://github.com/nickcharlton/nickcharlton
- Loading branch information
1 parent
ef3d3f3
commit 12b909b
Showing
17 changed files
with
1,172 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
name: Test | ||
on: [push] | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Ruby | ||
uses: ruby/setup-ruby@v1 | ||
with: | ||
bundler-cache: true | ||
- name: Install dependencies | ||
run: bundle install | ||
- name: Run tests | ||
run: bundle exec rspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--- | ||
name: Update README | ||
|
||
on: | ||
workflow_dispatch: | ||
schedule: | ||
- cron: '0 11 * * *' | ||
|
||
jobs: | ||
update: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Ruby | ||
uses: ruby/setup-ruby@v1 | ||
with: | ||
bundler-cache: true | ||
- name: Install dependencies | ||
run: bundle install | ||
- name: Update README | ||
run: |- | ||
bin/update_readme | ||
cat profile/README.md | ||
- name: Commit and push if changed | ||
run: |- | ||
git diff | ||
git config --global user.email "[email protected]" | ||
git config --global user.name "README Bot" | ||
git add -A | ||
git commit -m "Updated content" || exit 0 | ||
git push |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.bundle | ||
vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ruby-3.3.6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
source "https://rubygems.org" | ||
|
||
gem "excon" | ||
gem "feedjira" | ||
|
||
group :development, :test do | ||
gem "rspec" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
crass (1.0.6) | ||
diff-lcs (1.5.1) | ||
excon (1.2.2) | ||
feedjira (3.2.3) | ||
loofah (>= 2.3.1, < 3) | ||
sax-machine (>= 1.0, < 2) | ||
loofah (2.23.1) | ||
crass (~> 1.0.2) | ||
nokogiri (>= 1.12.0) | ||
nokogiri (1.17.2-aarch64-linux) | ||
racc (~> 1.4) | ||
nokogiri (1.17.2-arm-linux) | ||
racc (~> 1.4) | ||
nokogiri (1.17.2-arm64-darwin) | ||
racc (~> 1.4) | ||
nokogiri (1.17.2-x86-linux) | ||
racc (~> 1.4) | ||
nokogiri (1.17.2-x86_64-darwin) | ||
racc (~> 1.4) | ||
nokogiri (1.17.2-x86_64-linux) | ||
racc (~> 1.4) | ||
racc (1.8.1) | ||
rspec (3.13.0) | ||
rspec-core (~> 3.13.0) | ||
rspec-expectations (~> 3.13.0) | ||
rspec-mocks (~> 3.13.0) | ||
rspec-core (3.13.2) | ||
rspec-support (~> 3.13.0) | ||
rspec-expectations (3.13.3) | ||
diff-lcs (>= 1.2.0, < 2.0) | ||
rspec-support (~> 3.13.0) | ||
rspec-mocks (3.13.2) | ||
diff-lcs (>= 1.2.0, < 2.0) | ||
rspec-support (~> 3.13.0) | ||
rspec-support (3.13.2) | ||
sax-machine (1.3.2) | ||
|
||
PLATFORMS | ||
aarch64-linux | ||
arm-linux | ||
arm64-darwin | ||
x86-linux | ||
x86_64-darwin | ||
x86_64-linux | ||
|
||
DEPENDENCIES | ||
excon | ||
feedjira | ||
rspec | ||
|
||
BUNDLED WITH | ||
2.5.23 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require "bundler" | ||
|
||
Bundler.require | ||
|
||
$:.push File.expand_path("../lib", __dir__) | ||
|
||
require "github_readme" | ||
|
||
readme = Readme.new("profile/README.md") | ||
blog = RssFeed.new(url: "https://feeds.feedburner.com/GiantRobotsSmashingIntoOtherGiantRobots") | ||
|
||
readme.update(section: "blog", items: blog.take(5)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class FeedItem | ||
attr_accessor :id, :title, :url, :updated_at, :created_at | ||
|
||
def initialize(id:, title:, url:, created_at:, updated_at:) | ||
@id = id | ||
@title = title | ||
@url = url | ||
@created_at = created_at | ||
@updated_at = updated_at | ||
end | ||
|
||
def to_readme_line | ||
"[#{title}](#{url})\n" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require "excon" | ||
|
||
require "feed_item" | ||
require "rss_feed" | ||
require "readme" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
class Readme | ||
def initialize(file_path) | ||
@file_path = file_path | ||
end | ||
|
||
def update(section:, items:) | ||
content = items.map(&:to_readme_line).join("\n") | ||
new_contents = insert(file_contents, section, content) | ||
File.write(file_path, new_contents) | ||
end | ||
|
||
private | ||
|
||
attr_reader :file_path | ||
|
||
def file_contents | ||
File.read(file_path) | ||
end | ||
|
||
def insert(document, marker, content) | ||
replacement = <<~REPLACEMENT | ||
<!-- #{marker} starts --> | ||
#{content} | ||
<!-- #{marker} ends --> | ||
REPLACEMENT | ||
|
||
document.gsub( | ||
/<!\-\- #{marker} starts \-\->.*<!\-\- #{marker} ends \-\->/m, | ||
replacement.chomp | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require "json" | ||
require "excon" | ||
require "feedjira" | ||
|
||
class RssFeed | ||
include Enumerable | ||
|
||
def initialize(url:) | ||
@url = url | ||
end | ||
|
||
def each | ||
feed.entries.each do |entry| | ||
yield FeedItem.new( | ||
id: entry.id, | ||
title: entry.title, | ||
url: entry.url, | ||
created_at: entry.published, | ||
updated_at: entry.updated | ||
) | ||
end | ||
end | ||
|
||
private | ||
|
||
attr_reader :url | ||
|
||
def feed | ||
@feed ||= | ||
begin | ||
client = Excon.new(url) | ||
response = client.get | ||
Feedjira.parse(response.body) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require "spec_helper" | ||
require "github_readme" | ||
|
||
RSpec.describe FeedItem do | ||
describe "#to_readme_line" do | ||
it "is a markdown link to the feed item" do | ||
feed_item = described_class.new( | ||
id: nil, | ||
title: "Blog Post", | ||
url: "http://example.com", | ||
created_at: nil, | ||
updated_at: nil, | ||
) | ||
|
||
expect(feed_item.to_readme_line).to eq( | ||
"[Blog Post](http://example.com)\n", | ||
) | ||
end | ||
end | ||
end |
Oops, something went wrong.