Skip to content

Commit

Permalink
Merge pull request #4681 from galaxyproject/jamnapari-ordinal
Browse files Browse the repository at this point in the history
Implement GTN News posting via Google Form
  • Loading branch information
nomadscientist authored Jan 29, 2024
2 parents 2b161aa + b4167ba commit bd624fa
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 1 deletion.
53 changes: 53 additions & 0 deletions .github/workflows/google-form.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: "[Cron] Update news from Google Form"
on:
workflow_dispatch:
schedule:
- cron: '21 10 * * *'
jobs:
runner-job:
runs-on: ubuntu-latest
# Only run on main repo on and PRs that match the main repo.
if: |
github.repository == 'galaxyproject/training-material' &&
(github.event_name != 'pull_request' ||
github.event.pull_request.head.repo.full_name == github.repository)
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 1

# BEGIN Dependencies
- uses: ruby/setup-ruby@v1
with:
ruby-version: "3.0"
- uses: actions/cache@v2
with:
path: |
vendor/bundle
key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
restore-keys: |
${{ runner.os }}-gems-
- name: Install dependencies
run: |
gem install bundler
bundle config path vendor/bundle
bundle install --jobs 4 --retry 3
bundle pristine ffi
# END Dependencies

- name: Update Shortlinks
id: generate
run: |
ruby bin/google-form-news.rb >> $GITHUB_OUTPUT

- name: Create Pull Request
# If it's not a Pull Request then commit any changes as a new PR.
if: |
github.event_name != 'pull_request' &&
steps.generate.outputs.new_ids != ''
uses: peter-evans/create-pull-request@v3
with:
title: Import news posts from Google Form
branch-suffix: timestamp
commit-message: New News Post!
add-paths: news/_posts/
71 changes: 71 additions & 0 deletions bin/google-form-news.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'yaml'
require 'net/http'
require 'csv'
require 'date'

# Fetch data from a google sheet
url = 'https://docs.google.com/spreadsheets/d/1KJsQpZsUfaZh-a8jLx0gNymaQxvSNForrekEgIzF3Eo/export?format=tsv'
data = `curl -sL "#{url}"`

contributions_keys = %w[Authorship Editing Testing Infrastructure Translation Funding]

data = CSV.parse(data, col_sep: "\t", headers: true, quote_char: '|')

data.each do |row|
# Parse
# 29/01/2024 14:04:47
post_date = DateTime.strptime(row['Timestamp'], '%d/%m/%Y %H:%M:%S')
filename = "news/_posts/#{post_date.strftime('%Y-%m-%d')}-#{row['Title'].downcase.gsub(/[^a-z0-9\s]/i, '').gsub(
/\s+/, '-'
)}.md"

# Skip some testing posts
if (row['Title'] == 'TESTING') || (row['Title'] == "Wendi's Dog is the Best")
puts "Skipping #{filename} as it is a test post"
next
end

# Don't overwrite existing posts
if File.exist?(filename)
puts "Skipping #{filename} as it already exists"
next
end

puts "Creating #{filename}"

post_metadata = {
'title' => row['Title'],
'layout' => 'news',
'tags' => row['Tags'].split(',').map(&:strip),
'from_google_form' => true,
'contributions' => {}
}

contributions_keys.each do |key|
post_metadata['contributions'][key.downcase] = row[key].split(',').map(&:strip) if row[key]
end

if row['Optional Cover Image']
post_metadata['cover_image'] = row['Optional Cover Image']
post_metadata['cover_image_alt'] = row['Cover Image Alternative Text']
end

if row['Link to a specific tutorial you wish to push people to view']
post_metadata['tutorial'] = row['Link to a specific tutorial you wish to push people to view']
end

if row['Link for a non-tutorial thing you want to push people to view']
post_metadata['link'] = row['Link for a non-tutorial thing you want to push people to view']
end

# Serialise to a file

File.open(filename, 'w') do |file|
file.puts YAML.dump(post_metadata)
file.puts "---\n"
file.puts row['Blog Post'].gsub(' ', "\n\n")
end
end
7 changes: 7 additions & 0 deletions bin/schema-news.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,10 @@ mapping:
enum:
- true
- false
from_google_form:
type: bool
description: |
A boolean tracking in an automated way if this news post was generated via the GTN's News Google Form. Please do not add this manually.
enum:
- true
- false
6 changes: 5 additions & 1 deletion faqs/gtn/gtn_news_create_post.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ If you have created a new tutorial, running an event, published a paper around t

News items will show up on the [GTN homepage]({% link index.md %}) and in the [GTN news feed]({% link news.md %}).

**Creating the news post**
**Creating the news post: The Easy Way**

[Fill out this Google Form](https://forms.gle/6SRAVcppzieef7Zz9). Every day our bot will import the news posts submitted via this Google Form, and we will process them, perhaps requesting small changes, so we recommend that you have a GitHub account already.

**For Advanced Users**

Have a look at the existing news items in the [`news/_posts/` folder](https://github.com/galaxyproject/training-material/tree/main/news/_posts) of the GTN repository for some examples.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
title: Simplified GTN News submission via Google Form
layout: news
tags:
- gtn infrastructure
- new feature
- automation
from_google_form: true
contributions:
authorship:
- hexylena
testing:
- nomadscientist
infrastructure:
- hexylena
link: https://forms.gle/TqGTr6y46wrJDri7A
---
Based on user feedback of the difficulties of the GTN news submission process we have significantly simplified and removed the need for manually editing a YAML file by providing a quick and easy [Google Form](https://forms.gle/TqGTr6y46wrJDri7A)

Any news submitted via this form will be reviewed by the GTN maintainers, and, when linting is passing, merged.

So if you have some cool training news you want to share, then please let us know!

*Fun Fact*: This news post was prepared in the new Google Form.

0 comments on commit bd624fa

Please sign in to comment.