Skip to content

Commit

Permalink
Merge pull request #5 from oleg-nenashev/lts-backports
Browse files Browse the repository at this point in the history
Make the weekly.yml link in lts-backports-changelog optional + Support HTTPS URLs as a source of weekly.yml in lts-backports-changelog+ Fix failures of lts-backports-changelog on platforms where bash is not a default shell
  • Loading branch information
oleg-nenashev committed Nov 26, 2019
2 parents 483ecab + 643576d commit b3e3ba3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
FROM ruby

RUN apt-get update && apt-get upgrade -y && apt-get install -y jq && rm -rf /var/lib/apt/lists/*

COPY generate-jenkins-changelog.rb /jenkins-changelog-generator/bin/generate-jenkins-changelog
COPY lts-backports-changelog.rb /jenkins-changelog-generator/bin/lts-backports-changelog
COPY docker-runner.rb /jenkins-changelog-generator/bin/jenkins-changelog-generator
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ docker run -e GITHUB_AUTH=${GITHUB_AUTH} -v $(pwd):/github/workspace --rm jenkin
# lts-backports-changelog

This tool can be used to generate an LTS changelog for all the backported issues (labeled `2.xyz.w-fixed` in Jira) with corresponding changelog entries in the weekly changelog YAML file.
Weekly changelog YAML is optional, it will be downloaded from the [jenkins.io repository](https://github.com/jenkins-infra/jenkins.io/blob/master/content/_data/changelogs/weekly.yml) if not specified.

## Usage in CLI

Expand All @@ -62,5 +63,5 @@ export JIRA_AUTH=jira_username:jira_password
Example:

```sh
docker run -e GITHUB_AUTH=${GITHUB_AUTH} -e CHANGELOG_TYPE=lts -v $(pwd):/github/workspace --rm jenkins/core-changelog-generator 2.109.2
docker run -e GITHUB_AUTH=${GITHUB_AUTH} -e JIRA_AUTH=${JIRA_AUTH} -e CHANGELOG_TYPE=lts -v $(pwd):/github/workspace --rm jenkins/core-changelog-generator 2.109.2
```
27 changes: 22 additions & 5 deletions lts-backports-changelog.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
#!/usr/bin/env ruby

require 'yaml'
require "open-uri"
require 'shellwords'

git_repo = Dir.pwd

issues = []

curl_auth = ENV['JIRA_AUTH']

if ARGV.length != 2
puts "Usage: generate-lts-changelog.rb <LTS version> <weekly.yml>"
if ARGV.length < 1 || ARGV.length > 2
puts "Usage: generate-lts-changelog.rb <LTS version> [weekly.yml]"
puts ""
puts "Missing argument <version> and/or <weekly.yml>"
puts "Default weekly.yml: https://github.com/jenkins-infra/jenkins.io/blob/master/content/_data/changelogs/weekly.yml"
puts ""
puts "ERROR: Wrong argument number"
puts "To generate the changelog for an LTS release:"
puts " generate-lts-changelog.rb 2.164.3 /path/to/jenkins.io/content/_data/changelogs/weekly.yml"
puts ""
exit
end

Expand All @@ -22,11 +27,23 @@

weekly_changelog_file = ARGV[1]

backports_str = `set -o pipefail ; curl --fail -u #{curl_auth} -X POST --data '{"startAt":0, "maxResults":1000,"fields": ["key"], "jql": "labels = #{lts}-fixed" }' -H "Content-Type: application/json" https://issues.jenkins-ci.org/rest/api/2/search | jq -r '.issues[] | .key'`
command = "set -o pipefail ; curl --fail -u #{curl_auth} -X POST --data '{\"startAt\":0, \"maxResults\":1000,\"fields\": [\"key\"], \"jql\": \"labels = #{lts}-fixed\" }' -H \"Content-Type: application/json\" https://issues.jenkins-ci.org/rest/api/2/search | jq -r '.issues[] | .key'"
escaped_command = Shellwords.escape(command)
backports_str = `bash -c #{escaped_command}`

backports = backports_str.lines.collect { |x| x.chomp }

changelog = YAML.load_file(weekly_changelog_file)
if weekly_changelog_file == nil
puts "WARNING: Weekly changelog YAML is not specified. Using https://github.com/jenkins-infra/jenkins.io/blob/master/content/_data/changelogs/weekly.yml"
weekly_changelog_file = "https://raw.githubusercontent.com/jenkins-infra/jenkins.io/master/content/_data/changelogs/weekly.yml"
end

if weekly_changelog_file =~ /https:\/\//
yaml_content = open(weekly_changelog_file){|f| f.read}
changelog = YAML::load(yaml_content)
else
changelog = YAML.load_file(weekly_changelog_file)
end

backported_issues = []

Expand Down

0 comments on commit b3e3ba3

Please sign in to comment.