Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin info #384

Closed
wants to merge 32 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
e4d795b
change fstab
kunwarsaluja May 15, 2024
9a88190
Update fstab.yaml
kunwarsaluja May 15, 2024
cd85c19
Update fstab.yaml
kunwarsaluja May 15, 2024
df705fd
Update fstab.yaml
kunwarsaluja May 15, 2024
ebdcb56
runbook gh action
shsteimer May 15, 2024
559957d
remove unused wf
shsteimer May 15, 2024
e9fd70c
update node version
shsteimer May 15, 2024
be819a0
file updation
shsteimer May 15, 2024
567b4b5
file updation
shsteimer May 15, 2024
bab6f18
file updation
shsteimer May 15, 2024
7fbf23f
file updation
shsteimer May 15, 2024
809c160
file updation
shsteimer May 15, 2024
71c8938
file updation
shsteimer May 15, 2024
c787469
file updation
shsteimer May 15, 2024
6f08c82
file updation
shsteimer May 15, 2024
79928a3
ignore node modules
shsteimer May 15, 2024
df20dcb
please work
shsteimer May 15, 2024
7e80517
please work
shsteimer May 15, 2024
a47eae7
please work
shsteimer May 15, 2024
041f582
please work
shsteimer May 15, 2024
02ff274
please work
shsteimer May 15, 2024
b63b730
token permits
shsteimer May 15, 2024
9ac8d4e
Update Runbook info
shsteimer May 15, 2024
42640b3
resturcture, get the first commit
shsteimer May 15, 2024
9ac5284
Merge pull request #1 from kunwarsaluja/firstCommit
shsteimer May 15, 2024
97792af
env info changes
shsteimer May 15, 2024
62d21c3
Merge branch 'firstCommit'
shsteimer May 15, 2024
e9f8a60
refactoring
shsteimer May 15, 2024
c9e4283
adding try catch
shsteimer May 15, 2024
3c9c057
env info with appropriate checks and fallbacks
shsteimer May 15, 2024
46e2fc9
Update Runbook info
shsteimer May 15, 2024
301f314
plugin info
kunwarsaluja May 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions .github/runbook/generate-runbook.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@

import { Octokit } from "octokit";
import { promises as fs } from 'fs';
import YAML from 'yaml'
import fetch from 'node-fetch';

const OCTOKIT_BASE_PARAMS = {
owner: "kunwarsaluja",
repo: "hackathon-runbook-stream",
headers: {
'X-GitHub-Api-Version': '2022-11-28'
}
};

const readRepoFileContents = async (filePath) => {
try {
const fileContents = await fs.readFile(`../../${filePath}`, {
encoding: 'utf8',
flag: 'r',
});
return fileContents;
} catch (e) {
console.error('failed reading file.', e)
return false;
}
};

const getEnvironmentInfo = async () => {
const envInfo = {
githubUrl: `https://github.com/${OCTOKIT_BASE_PARAMS.owner}/${OCTOKIT_BASE_PARAMS.repo}`,
sharepointUrl: '',
previewUrl: `http://main--${OCTOKIT_BASE_PARAMS.repo}--${OCTOKIT_BASE_PARAMS.owner}.hlx.page/`,
liveUrl: `http://main--${OCTOKIT_BASE_PARAMS.repo}--${OCTOKIT_BASE_PARAMS.owner}.hlx.live/`,
};

const fsTab = await readRepoFileContents('fstab.yaml');
if (fsTab) {
const data = YAML.parse(fsTab);
envInfo.sharepointUrl = data.mountpoints['/'];
}


const resp = await fetch(`https://admin.hlx.page/status/${OCTOKIT_BASE_PARAMS.owner}/${OCTOKIT_BASE_PARAMS.repo}/main`);
if (resp.ok) {
const json = await resp.json();
envInfo.previewUrl = json.preview.url;
envInfo.liveUrl = json.live.url;
}

return envInfo;
};

const getPluginInfo = async () => {
const resp = await fetch(`https://admin.hlx.page/sidekick/${OCTOKIT_BASE_PARAMS.owner}/${OCTOKIT_BASE_PARAMS.repo}/main/config.json`);
const json = await resp.json();

const plugins = json.plugins || [];

const pluginTitles = plugins
.filter(plugin => plugin.title) // Filter out plugins without a title
.map(plugin => plugin.title);

return {
pluginTitles: pluginTitles
};
};

const getFirstCommit = async (octokit) => {
const commits = await octokit.paginate("GET /repos/{owner}/{repo}/commits", {
...OCTOKIT_BASE_PARAMS,
path: '/scripts/scripts.js',
});
return commits.pop();
};

const main = async (token, targetDirectory) => {
const octokit = new Octokit({
auth: token,
});

const data = {};
data.environmentInfo = await getEnvironmentInfo();
data.pluginInfo = await getPluginInfo();
data.firstCommit = await getFirstCommit(octokit);

try {
fs.access(targetDirectory, fs.constants.W_OK);
} catch {
await fs.mkdir(targetDirectory);
}
await fs.writeFile(`${targetDirectory}/runbook-info.json`, JSON.stringify(data, undefined, 2));
};

const token = process.argv[2];
main(process.env.TOKEN, '../../runbook').catch((e) => console.error(e));
Loading
Loading