Skip to content

Instantly share code, notes, and snippets.

@halkeye
Created May 2, 2020 19:43
Show Gist options
  • Save halkeye/ac8d97796ede68770c9db2b92d616774 to your computer and use it in GitHub Desktop.
Save halkeye/ac8d97796ede68770c9db2b92d616774 to your computer and use it in GitHub Desktop.
/* eslint-disable no-console */
const axios = require('axios');
const escapeStringRegexp = require('escape-string-regexp');
const {parse:parseUrl} = require('url');
const requestGET = (url) => {
return axios
.get(url)
.then((results) => {
if (results.status !== 200) {
throw results.data;
}
return results.data;
});
};
const pluginWikiUrlRe = /^https?:\/\/wiki.jenkins(?:-ci.org|.io)\/display\/(?:jenkins|hudson)\/([^/]*)\/?$/i;
requestGET('https://updates.jenkins.io/current/plugin-documentation-urls.json').then(urls => {
for (const [key, {url}] of Object.entries(urls)) {
if (!pluginWikiUrlRe.test(url)) { continue; }
const [other, page] = url.match(pluginWikiUrlRe);
console.log(`RewriteCond %{HTTP_USER_AGENT} !^jenkins-wiki-exporter/(.*)$`)
console.log(`RewriteRule "^${escapeStringRegexp(parseUrl(other).pathname).replace(/\+/g, '\+')}$" "https://plugins.jenkins.io/${key}" [NC,L,QSA,R=301]`);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment