Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add recent blog posts to the organisation README #2

Merged
merged 1 commit into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/workflows/tests.yml
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
31 changes: 31 additions & 0 deletions .github/workflows/update_readme.yml
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 "actions@users.noreply.github.com"
git config --global user.name "README Bot"
git add -A
git commit -m "Updated content" || exit 0
git push
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.bundle
vendor
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ruby-3.4.1
8 changes: 8 additions & 0 deletions Gemfile
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
57 changes: 57 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
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)
mini_portile2 (2.8.8)
nokogiri (1.18.1)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
nokogiri (1.18.1-aarch64-linux-gnu)
racc (~> 1.4)
nokogiri (1.18.1-arm-linux-gnu)
racc (~> 1.4)
nokogiri (1.18.1-arm64-darwin)
racc (~> 1.4)
nokogiri (1.18.1-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.18.1-x86_64-linux-gnu)
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
14 changes: 14 additions & 0 deletions bin/update_readme
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))
15 changes: 15 additions & 0 deletions lib/feed_item.rb
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
5 changes: 5 additions & 0 deletions lib/github_readme.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require "excon"

require "feed_item"
require "rss_feed"
require "readme"
32 changes: 32 additions & 0 deletions lib/readme.rb
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
36 changes: 36 additions & 0 deletions lib/rss_feed.rb
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
9 changes: 9 additions & 0 deletions profile/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ products at every stage of the product lifecycle. Since 2003, we have produced
high-quality products for over [1,000 clients][3]. We are proud to leave every
project with a stronger team and improved processes.

### Writing

<!-- blog starts -->
[Why UX is more important than UI](https://thoughtbot.com/blog/why-ux-is-more-important-than-ui)

[The digital nomad thoughtbottle](https://thoughtbot.com/blog/the-digital-nomad-thoughtbottle)

<!-- blog ends -->

[1]: https://thoughtbot.com
[2]: https://thoughtbot.com/services
[3]: https://thoughtbot.com/case-studies
20 changes: 20 additions & 0 deletions spec/feed_item_spec.rb
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
Loading
Loading