Commit 6b57b5ea authored by Craig Miskell's avatar Craig Miskell Committed by Zeger-Jan van de Weg

Experimental RSS feed for the handbook changelog

parent a9bdf702
......@@ -168,6 +168,16 @@ generate-handbook-changelog:
tags:
- gitlab-org
generate-handbook-changelog-rss:
stage: build
script:
- bundle exec bin/generate_handbook_changelog_rss
allow_failure: true
only:
- schedules
tags:
- gitlab-org
.build_base: &build_base
before_script:
- find source/images/team -type f ! -name '*-crop.jpg' -delete
......
......@@ -35,6 +35,7 @@ gem 'faraday_middleware-parse_oj', '~> 0.3'
# Handbook CHANGELOG generation
gem 'gitlab'
gem "rss", "~> 0.2.8"
# Greenhouse API
gem 'greenhouse_io'
......
......@@ -199,6 +199,7 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-support (3.8.0)
rss (0.2.8)
rubocop (0.59.2)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
......@@ -261,6 +262,7 @@ DEPENDENCIES
mini_racer (~> 0.2)
nokogiri (>= 1.10.3)
rspec (~> 3.5)
rss (~> 0.2.8)
rubocop (~> 0.59.0)
sassc
selenium-webdriver
......
......@@ -5,11 +5,6 @@ require 'date'
require 'gitlab'
require_relative '../lib/changelog'
Gitlab.configure do |config|
config.endpoint = 'https://gitlab.com/api/v4'
config.private_token = ENV.fetch('PRIVATE_TOKEN')
end
REL_FILE_PATH = "source/handbook/CHANGELOG.html.md"
FILE_PATH = File.expand_path(REL_FILE_PATH)
......
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'date'
require 'gitlab'
require_relative '../lib/changelog'
REL_FILE_PATH = "source/handbook/changelog.rss"
FILE_PATH = File.expand_path(REL_FILE_PATH)
Changelog::RSS.create(FILE_PATH)
CM_ID = 3623028
PROJECT_ID = Changelog::WWW_GITLAB_COM_PROJECT_ID
TARGET_BRANCH = 'master'
GENERATED_TIMESTAMP = DateTime.now.to_date.to_s
SOURCE_BRANCH = "changelog-rss-#{GENERATED_TIMESTAMP}"
Gitlab.create_branch(PROJECT_ID, SOURCE_BRANCH, TARGET_BRANCH)
Gitlab.create_commit(PROJECT_ID, SOURCE_BRANCH, "Update changelog RSS feed for #{GENERATED_TIMESTAMP}",
[action: 'update', file_path: REL_FILE_PATH, content: File.read(FILE_PATH)])
mr = Gitlab.create_merge_request(PROJECT_ID, "Update changelog RSS feed for #{GENERATED_TIMESTAMP}",
source_branch: SOURCE_BRANCH, target_branch: TARGET_BRANCH,
assignee_id: CM_ID, remove_source_branch: true,
labels: 'no changelog')
Gitlab.accept_merge_request(PROJECT_ID, mr.iid, merge_when_pipeline_succeeds: true)
......@@ -5,6 +5,12 @@ require 'date'
require_relative 'changelog/merge_request'
require_relative 'changelog/file'
require_relative 'changelog/rss'
Gitlab.configure do |config|
config.endpoint = 'https://gitlab.com/api/v4'
config.private_token = ENV.fetch('PRIVATE_TOKEN')
end
module Changelog
WWW_GITLAB_COM_PROJECT_ID = 7764
......
......@@ -29,10 +29,16 @@ module Changelog
end
def to_s
"- [!#{iid}](https://gitlab.com/gitlab-com/www-gitlab-com/merge_requests/#{iid}) #{title}"
"- [!#{iid}](#{link}) #{title}"
end
private
def link
"https://gitlab.com/gitlab-com/www-gitlab-com/merge_requests/#{iid}"
end
def author
gitlab_merge_request.author.name
end
def changes
return @changes if defined?(@changes)
......@@ -49,6 +55,8 @@ module Changelog
end
end
private
def changes_handbook?
return false unless changes&.has_key?('changes')
......
# frozen_string_literal: true
require 'rss'
require 'cgi'
module Changelog
class RSS
def self.create(path)
new(path).write!
end
def initialize(path)
@path = path
end
def write!
rss = ::RSS::Maker.make("atom") do |maker|
maker.channel.author = "GitLab Inc."
maker.channel.updated = Time.now.to_s
maker.channel.about = "https://about.gitlab.com/handbook/"
maker.channel.title = "GitLab Handbook Changelog Feed"
merge_requests.each do |mr|
maker.items.new_item do |item|
item.link = mr.link
item.title = mr.title
item.author = mr.author
item.updated = mr.merged_at
# Enhancement opportunity: Make this a lot prettier. Good enough first iteration, but
# can do with a lot of work
item.content.type = "html"
item.content.content = mr.changes['changes'].map do |change|
"<b>#{change['new_path']}</b>:<br>
#{CGI.escapeHTML(change['diff']).gsub("\n", '<br>').gsub("\u0010", '<br>')}"
end.join("<br><br>")
end
end
end
::File.write(@path, rss)
end
private
def merge_requests
Gitlab
.merge_requests(project_id, state: 'merged') # created_at descending implied
.paginate_with_limit(200)
.map { |mr| MergeRequest.new(mr.iid, mr.title, mr.labels) }
.select(&:changelog_entry?)
end
def project_id
Changelog::WWW_GITLAB_COM_PROJECT_ID
end
end
end
module Gitlab
class PaginatedResponse
def paginate_with_limit(limit)
response = block_given? ? nil : []
count = 0
each_page do |page|
if block_given?
page.each do |item|
yield item
count += 1
break if count >= limit
end
else
response += page[0, limit - count]
count = response.length
end
break if count >= limit
end
response
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment