Skip to content

Instantly share code, notes, and snippets.

@zoetrope69
Last active July 30, 2020 11:09
Show Gist options
  • Save zoetrope69/dc100f82064c236ab3d31d6f11c07793 to your computer and use it in GitHub Desktop.
Save zoetrope69/dc100f82064c236ab3d31d6f11c07793 to your computer and use it in GitHub Desktop.
CircleCI Release Bookmarklet
# minified
javascript:!function(){let e=0;const r={philmitchell:["blue"],grant:["blue"],ernie:["grey"],wolfgang:["green"],babyChick:["yellow"],bobRoss:["blue","white","grey","green","brown","blue"],rainbow:["red","orange","yellow","green","blue","purple","pink"],pocPrideFlag:["black","brown","red","orange","yellow","green","blue","purple","pink"],agenderFlag:["black","grey","white","green","white","grey","black"],aromanticFlag:["green","green","white","grey","black"],asexualFlag:["black","grey","white","purple"],bisexualFlag:["pink","purple","blue"],genderfluidFlag:["pink","white","purple","black","blue"],genderQueerFlag:["purple","white","green"],intersexFlag:["yellow","purple","yellow"],lesbianFlag:["red","orange","white","pink","purple"],nonBinaryFlag:["yellow","white","purple","black"],pansexualFlag:["pink","yellow","blue"],polysexualFlag:["pink","green","blue"],transFlag:["blue","pink","white","pink","blue"]},l=[...r.rainbow,...Object.keys(r)],n=l[Math.floor(Math.random()*l.length)],a={philmitchell:"philmitchell",grant:"grant",ernie:"ernie",wolfgang:"wolfgang",babyChick:"baby_chick",bobRoss:"bob-ross",rainbow:"rainbow",pocPrideFlag:"pride-poc",agenderFlag:"pride-agender",aromanticFlag:"pride-aromantic",asexualFlag:"pride-asexual",bisexualFlag:"pride-bisexual",genderfluidFlag:"pride-genderfluid",genderQueerFlag:"pride-genderqueer",intersexFlag:"pride-intersex",lesbianFlag:"pride-lesbian-alt",nonBinaryFlag:"pride-nonbinary",pansexualFlag:"pride-pansexual",polysexualFlag:"pride-polysexual",transFlag:"pride-transgender"}[n];function t(){if(Object.keys(r).includes(n)){const l=r[n],a=l[e];return e+1===l.length?e=0:e+=1,a}return n}const i=[...document.querySelectorAll(".css-1kdw3a0")].map(e=>{return{releaseStatus:e.querySelector(".css-1jwka9i")?.innerText,releaseAuthor:e.querySelector(".css-1enh3hr")?.alt,releaseText:e.querySelector(".css-a2yhqb")?.innerText,releaseBranchAndJob:e.querySelector(".css-12kark1")?.innerText}}).filter(({releaseBranchAndJob:e,releaseText:r})=>{const l="master / test_and_build"===e,n=r&&r.length>0;return l&&n}),o=i.findIndex(({releaseStatus:e})=>"SUCCEEDED"===e),g=i.slice(0,o);if(0===g.length){const e=document.createElement("div");return e.innerHTML="Nothing to deploy...",void document.body.prepend(e)}let s=a?`:${a}: <br />`:"";s+=`:worm-vert-head-${t()}: <br />`,s+=g.map(({releaseAuthor:e,releaseText:r},l)=>{let n=`:worm-vert-body-${t()}: • ${(e=>{const r=/\(#(.+)\)/g.exec(e);if(!r)return e;const[l,n]=r,a=r.index,t=a+l.length;return e.substr(0,a)+`(<a href='${`https://github.com/CondeNast/rocket/pull/${n}`}'>#${n}</a>)`+e.substr(t)})(r)}`;return e&&(n+=` @${e}`),n}).join("<br />"),s+=`<br /> :worm-vert-tail-${t()}: <br />`;const u=document.createElement("div");u.innerHTML=s,document.body.prepend(u)}();
# full
javascript:(function(){
const injectPRLinkIntoReleaseText = (releaseText) => {
const pullRequestHashRegex = /\(#(.+)\)/g.exec(releaseText);
if (!pullRequestHashRegex) {
return releaseText;
}
const [fullMatch, hashNumber] = pullRequestHashRegex;
const hashNumberStartPosition = pullRequestHashRegex.index;
const hasNumberEndPosition = hashNumberStartPosition + fullMatch.length;
const textBeforePullRequestHash = releaseText.substr(0, hashNumberStartPosition);
const textAfterPullRequestHash = releaseText.substr(hasNumberEndPosition);
const urlToRocketPullRequest = `https://github.com/CondeNast/rocket/pull/${hashNumber}`;
const linkToRocketPullRequest = `(<a href='${urlToRocketPullRequest}'>#${hashNumber}</a>)`;
return textBeforePullRequestHash + linkToRocketPullRequest + textAfterPullRequestHash;
};
let colorCount = 0;
const colorLists = {
philmitchell: ["blue"],
grant: ["blue"],
ernie: ["grey"],
wolfgang: ["green"],
babyChick: ["yellow"],
bobRoss: ["blue", "white", "grey", "green", "brown", "blue"],
rainbow: ["red", "orange", "yellow", "green", "blue", "purple", "pink"],
// pride
pocPrideFlag: ["black", "brown", "red", "orange", "yellow", "green", "blue", "purple", "pink"],
agenderFlag: ["black", "grey", "white", "green", "white", "grey", "black"],
aromanticFlag: ["green", "green", "white", "grey", "black"],
asexualFlag: ["black", "grey", "white", "purple"],
bisexualFlag: ["pink", "purple", "blue"],
genderfluidFlag: ["pink", "white", "purple", "black", "blue"],
genderQueerFlag: ["purple", "white", "green"],
intersexFlag: ["yellow", "purple", "yellow"],
lesbianFlag: ["red", "orange", "white", "pink", "purple"],
nonBinaryFlag: ["yellow", "white", "purple", "black"],
pansexualFlag: ["pink", "yellow", "blue"],
polysexualFlag: ["pink", "green", "blue"],
transFlag: ["blue", "pink", "white", "pink", "blue"]
};
const emojiMap = {
philmitchell: 'philmitchell',
grant: 'grant',
ernie: 'ernie',
wolfgang: 'wolfgang',
babyChick: 'baby_chick',
bobRoss: 'bob-ross',
rainbow: 'rainbow',
// pride
pocPrideFlag: 'pride-poc',
agenderFlag: 'pride-agender',
aromanticFlag: 'pride-aromantic',
asexualFlag: 'pride-asexual',
bisexualFlag: 'pride-bisexual',
genderfluidFlag: 'pride-genderfluid',
genderQueerFlag: 'pride-genderqueer',
intersexFlag: 'pride-intersex',
lesbianFlag: 'pride-lesbian-alt',
nonBinaryFlag: 'pride-nonbinary',
pansexualFlag: 'pride-pansexual',
polysexualFlag: 'pride-polysexual',
transFlag: 'pride-transgender'
};
const wormTypes = [...colorLists.rainbow, ...Object.keys(colorLists)];
const wormType = wormTypes[Math.floor(Math.random() * wormTypes.length)];
const mainEmoji = emojiMap[wormType];
function getWormColor() {
const isAColorList = Object.keys(colorLists).includes(wormType);
if (isAColorList) {
const colorList = colorLists[wormType];
const newColor = colorList[colorCount];
if (colorCount + 1 === colorList.length) {
colorCount = 0;
} else {
colorCount += 1;
}
return newColor;
} else {
return wormType;
}
}
const jobs = [...document.querySelectorAll(".css-1kdw3a0")].map(e => {
const releaseStatus = e.querySelector('.css-1jwka9i')?.innerText;
const releaseAuthor = e.querySelector('.css-1enh3hr')?.alt;
const releaseText = e.querySelector('.css-a2yhqb')?.innerText;
const releaseBranchAndJob = e.querySelector('.css-12kark1')?.innerText;
return { releaseStatus, releaseAuthor, releaseText, releaseBranchAndJob };
});
const filteredJobs = jobs.filter(({ releaseBranchAndJob, releaseText }) => {
const isMasterTestAndBuildJob = releaseBranchAndJob === 'master / test_and_build';
const hasReleaseText = releaseText && releaseText.length > 0;
return isMasterTestAndBuildJob && hasReleaseText;
});
const firstJobSucceededIndex = filteredJobs.findIndex(({ releaseStatus }) => releaseStatus === 'SUCCEEDED');
const jobsUpTilFirstSucceeded = filteredJobs.slice(0, firstJobSucceededIndex);
if (jobsUpTilFirstSucceeded.length === 0) {
const divEl = document.createElement("div");
divEl.innerHTML = 'Nothing to deploy...';
document.body.prepend(divEl);
return;
}
let text = mainEmoji ? `:${mainEmoji}: <br />` : '';
// add worm head
text += `:worm-vert-head-${getWormColor()}: <br />`;
text += jobsUpTilFirstSucceeded
.map(({ releaseAuthor, releaseText }, index) => {
let itemText = `:worm-vert-body-${getWormColor()}: • ${injectPRLinkIntoReleaseText(releaseText)}`;
if (releaseAuthor) {
itemText += ` @${releaseAuthor}`;
}
return itemText;
})
.join("<br />");
// add worm tail
text += `<br /> :worm-vert-tail-${getWormColor()}: <br />`;
const divEl = document.createElement("div");
divEl.innerHTML = text;
document.body.prepend(divEl);
})();
@zoetrope69
Copy link
Author

zoetrope69 commented Feb 25, 2020

How to use this script

Installation

Use this minified version:

javascript:!function(){let e=0;const r={philmitchell:["blue"],grant:["blue"],ernie:["grey"],wolfgang:["green"],babyChick:["yellow"],bobRoss:["blue","white","grey","green","brown","blue"],rainbow:["red","orange","yellow","green","blue","purple","pink"],pocPrideFlag:["black","brown","red","orange","yellow","green","blue","purple","pink"],agenderFlag:["black","grey","white","green","white","grey","black"],aromanticFlag:["green","green","white","grey","black"],asexualFlag:["black","grey","white","purple"],bisexualFlag:["pink","purple","blue"],genderfluidFlag:["pink","white","purple","black","blue"],genderQueerFlag:["purple","white","green"],intersexFlag:["yellow","purple","yellow"],lesbianFlag:["red","orange","white","pink","purple"],nonBinaryFlag:["yellow","white","purple","black"],pansexualFlag:["pink","yellow","blue"],polysexualFlag:["pink","green","blue"],transFlag:["blue","pink","white","pink","blue"]},l=[...r.rainbow,...Object.keys(r)],n=l[Math.floor(Math.random()*l.length)],a={philmitchell:"philmitchell",grant:"grant",ernie:"ernie",wolfgang:"wolfgang",babyChick:"baby_chick",bobRoss:"bob-ross",rainbow:"rainbow",pocPrideFlag:"pride-poc",agenderFlag:"pride-agender",aromanticFlag:"pride-aromantic",asexualFlag:"pride-asexual",bisexualFlag:"pride-bisexual",genderfluidFlag:"pride-genderfluid",genderQueerFlag:"pride-genderqueer",intersexFlag:"pride-intersex",lesbianFlag:"pride-lesbian-alt",nonBinaryFlag:"pride-nonbinary",pansexualFlag:"pride-pansexual",polysexualFlag:"pride-polysexual",transFlag:"pride-transgender"}[n];function t(){if(Object.keys(r).includes(n)){const l=r[n],a=l[e];return e+1===l.length?e=0:e+=1,a}return n}const i=[...document.querySelectorAll(".css-1kdw3a0")].map(e=>{return{releaseStatus:e.querySelector(".css-1jwka9i")?.innerText,releaseAuthor:e.querySelector(".css-1enh3hr")?.alt,releaseText:e.querySelector(".css-a2yhqb")?.innerText,releaseBranchAndJob:e.querySelector(".css-12kark1")?.innerText}}).filter(({releaseBranchAndJob:e,releaseText:r})=>{const l="master / test_and_build"===e,n=r&&r.length>0;return l&&n}),o=i.findIndex(({releaseStatus:e})=>"SUCCEEDED"===e),g=i.slice(0,o);if(0===g.length){const e=document.createElement("div");return e.innerHTML="Nothing to deploy...",void document.body.prepend(e)}let s=a?`:${a}: <br />`:"";s+=`:worm-vert-head-${t()}: <br />`,s+=g.map(({releaseAuthor:e,releaseText:r},l)=>{let n=`:worm-vert-body-${t()}: • ${(e=>{const r=/\(#(.+)\)/g.exec(e);if(!r)return e;const[l,n]=r,a=r.index,t=a+l.length;return e.substr(0,a)+`(<a href='${`https://github.com/CondeNast/rocket/pull/${n}`}'>#${n}</a>)`+e.substr(t)})(r)}`;return e&&(n+=` @${e}`),n}).join("<br />"),s+=`<br /> :worm-vert-tail-${t()}: <br />`;const u=document.createElement("div");u.innerHTML=s,document.body.prepend(u)}();

Install this script as a bookmark(let)

Usage

Go to a workflow branch such as: https://circleci.deployment.cni.digital/gh/CondeNast/workflows/rocket/tree/master

When you click the bookmarklet in Circle it'll inject all the releases at the top of the page.

This script gets all of the release in the page. You will need to:

  1. Work out which was the last successful and edit down to those
  2. Fix any incorrect tagging as Slack doesn't always match GitHub user info
  3. Update the head and tail of the wiggly wiggly worm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment