Skip to content

Commit c408268

Browse files
committed
Export ROOM_ZOOM info to GitHub
1 parent 0e7154b commit c408268

File tree

8 files changed

+186
-38
lines changed

8 files changed

+186
-38
lines changed

tools/appscript/add-custom-menu.mjs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ export default function () {
2222
.addItem('Retrieve latest published schedule (from GitHub)', 'importGrid')
2323
.addItem('Fetch event info, rooms, days, slots (from GitHub)', 'importMetadata')
2424
.addItem('Export event to files (HTML, JSON)', 'exportEventToFiles')
25-
.addItem('Push the global W3C IDs spreadsheet (to GitHub)', 'exportW3CMap')
26-
/*.addItem('Export event info, rooms, days, slots to GitHub', 'exportMetadata')*/
25+
.addItem('Export event, chairs and Zoom info to GitHub', 'exportMetadata')
2726
)
2827
.addToUi();
2928
}

tools/appscript/export-grid.mjs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
import { getProject } from './lib/project.mjs';
21
import reportError from './lib/report-error.mjs';
2+
import {
3+
getProject,
4+
syncProjectMetadataWithGitHub
5+
} from './lib/project.mjs';
36
import {
47
fetchProjectFromGitHub,
58
saveSessionMeetings,
69
saveSessionNote } from '../common/project.mjs';
710
import { exportMapping } from './lib/w3cid-map.mjs';
11+
import { exportRoomZoom } from './lib/room-zoom.mjs';
812

913
export default async function () {
1014
try {
@@ -84,10 +88,18 @@ export default async function () {
8488
}
8589
console.log('Export updates when needed... done');
8690

91+
console.log('Export project metadata...');
92+
await syncProjectMetadataWithGitHub(project, githubProject);
93+
console.log('Export project metadata... done');
94+
8795
console.log('Export W3CID_MAP mapping...');
8896
await exportMapping(project);
8997
console.log('Export W3CID_MAP mapping... done');
9098

99+
console.log('Export ROOM_ZOOM variable to GitHub...');
100+
await exportRoomZoom(project);
101+
console.log('Export ROOM_ZOOM variable to GitHub... done');
102+
91103
if (updated.length > 0 &&
92104
project.metadata.calendar &&
93105
project.metadata.calendar !== 'no') {

tools/appscript/export-metadata.mjs

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,58 @@
11
import reportError from './lib/report-error.mjs';
2+
import {
3+
getProject,
4+
syncProjectMetadataWithGitHub
5+
} from './lib/project.mjs';
6+
import {
7+
fetchProjectFromGitHub,
8+
exportProjectMetadata,
9+
serializeProjectMetadata
10+
} from '../common/project.mjs';
11+
import { exportMapping } from './lib/w3cid-map.mjs';
12+
import { exportRoomZoom } from './lib/room-zoom.mjs';
213

314

415
export default async function () {
516
try {
17+
console.log('Read data from spreadsheet...');
18+
const project = getProject(SpreadsheetApp.getActiveSpreadsheet());
19+
console.log('Read data from spreadsheet... done');
20+
21+
if (!project.metadata.reponame) {
22+
reportError(`No GitHub repository associated with the current document.
23+
24+
Make sure that the "GitHub repository name" parameter is set in the "Event" sheet.
25+
26+
Also make sure the targeted repository and project have been properly initialized.
27+
If not, ask François or Ian to run the required initialization steps.`);
28+
return;
29+
}
30+
31+
const repoparts = project.metadata.reponame.split('/');
32+
const repo = {
33+
owner: repoparts.length > 1 ? repoparts[0] : 'w3c',
34+
name: repoparts.length > 1 ? repoparts[1] : repoparts[0]
35+
};
36+
37+
console.log('Fetch data from GitHub...');
38+
const githubProject = await fetchProjectFromGitHub(
39+
repo.owner === 'w3c' ? repo.owner : `user/${repo.owner}`,
40+
repo.name,
41+
null
42+
);
43+
console.log('Fetch data from GitHub... done');
44+
645
console.log('Export metadata to GitHub...');
7-
console.log('- TODO: export metadata to GitHub');
46+
await syncProjectMetadataWithGitHub(project, githubProject);
847
console.log('Export metadata to GitHub... done');
948

10-
console.log('Report result...');
11-
console.log('- TODO: report result');
12-
console.log('Report result... done');
49+
console.log('Push the mapping table to the GitHub repository...');
50+
await exportMapping(project);
51+
console.log('Push the mapping table to the GitHub repository... done');
52+
53+
console.log('Export ROOM_ZOOM variable to GitHub...');
54+
await exportRoomZoom(project);
55+
console.log('Export ROOM_ZOOM variable to GitHub... done');
1356
}
1457
catch(err) {
1558
reportError(err.toString());

tools/appscript/export-w3cid-map.mjs

Lines changed: 0 additions & 29 deletions
This file was deleted.

tools/appscript/lib/project.mjs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { getSessionSections } from '../../common/session-sections.mjs';
2+
import { exportProjectMetadata } from '../../common/project.mjs';
23

34
/**
45
* Retrieve an indexed object that contains the list of sheets associated with
@@ -621,4 +622,27 @@ export async function saveSessionValidationInSheet(session, project) {
621622
session.validation.warning,
622623
session.validation.check
623624
]]);
625+
}
626+
627+
628+
export async function syncProjectMetadataWithGitHub(project, githubProject) {
629+
const metadata = {};
630+
let needsUpdate = false;
631+
for (const [key, val] of Object.entries(project.metadata)) {
632+
if (['fullType', 'reponame'].includes(key)) {
633+
continue;
634+
}
635+
metadata[key] = val;
636+
if (val !== githubProject.metadata[key]) {
637+
console.log(`- "${key}" metadata needs to be updated to "${val}"`);
638+
needsUpdate = true;
639+
}
640+
}
641+
642+
if (needsUpdate || project.title !== githubProject.title) {
643+
console.log('- export metadata to GitHub...');
644+
githubProject.metadata = metadata;
645+
githubProject.title = project.title;
646+
await exportProjectMetadata(githubProject);
647+
}
624648
}

tools/appscript/lib/room-zoom.mjs

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import { getEnvKey } from '../../common/envkeys.mjs';
2+
import wrappedFetch from '../../common/wrappedfetch.mjs';
3+
4+
export async function exportRoomZoom(project) {
5+
const repoparts = project.metadata.reponame.split('/');
6+
const repo = {
7+
owner: repoparts.length > 1 ? repoparts[0] : 'w3c',
8+
name: repoparts.length > 1 ? repoparts[1] : repoparts[0]
9+
};
10+
11+
const ROOM_ZOOM = {};
12+
for (const room of project.rooms) {
13+
if (room['Zoom link']) {
14+
ROOM_ZOOM[room.name] = {
15+
id: room['Zoom ID'],
16+
passcode: room['Zoom passcode'],
17+
link: room['Zoom link']
18+
};
19+
}
20+
}
21+
22+
console.log('- check whether the GitHub variable exists');
23+
const GRAPHQL_TOKEN = await getEnvKey('GRAPHQL_TOKEN');
24+
let res = await wrappedFetch(
25+
`https://api.github.com/repos/${repo.owner}/${repo.name}/actions/variables/ROOM_ZOOM`,
26+
{
27+
method: 'GET',
28+
headers: {
29+
'Authorization': `bearer ${GRAPHQL_TOKEN}`,
30+
'Accept': 'application/vnd.github+json'
31+
}
32+
}
33+
);
34+
if (res.status === 200) {
35+
console.log('- variable already exists, update it');
36+
res = await wrappedFetch(
37+
`https://api.github.com/repos/${repo.owner}/${repo.name}/actions/variables/ROOM_ZOOM`,
38+
{
39+
method: 'PATCH',
40+
headers: {
41+
'Content-Type': 'application/json',
42+
'Authorization': `bearer ${GRAPHQL_TOKEN}`,
43+
'Accept': 'application/vnd.github+json'
44+
},
45+
body: JSON.stringify({
46+
name: 'ROOM_ZOOM',
47+
value: JSON.stringify(ROOM_ZOOM, null, 2)
48+
})
49+
}
50+
);
51+
if (res.status !== 204) {
52+
throw new Error(`GitHub REST API server returned an unexpected HTTP status ${res.status}`);
53+
}
54+
}
55+
else if (res.status === 404) {
56+
console.log('- variable does not exist yet, create it');
57+
res = await wrappedFetch(
58+
`https://api.github.com/repos/${repo.owner}/${repo.name}/actions/variables`,
59+
{
60+
method: 'POST',
61+
headers: {
62+
'Content-Type': 'application/json',
63+
'Authorization': `bearer ${GRAPHQL_TOKEN}`,
64+
'Accept': 'application/vnd.github+json'
65+
},
66+
body: JSON.stringify({
67+
name: 'ROOM_ZOOM',
68+
value: JSON.stringify(ROOM_ZOOM, null, 2)
69+
})
70+
}
71+
);
72+
if (res.status !== 201) {
73+
throw new Error(`GitHub REST API server returned an unexpected HTTP status ${res.status}`);
74+
}
75+
}
76+
else {
77+
throw new Error(`GitHub REST API server returned an unexpected HTTP status ${res.status}`);
78+
}
79+
}

tools/appscript/main.mjs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import _importSessions from './import-sessions.mjs';
2424
import _importMetadata from './import-metadata.mjs';
2525
import _exportMetadata from './export-metadata.mjs';
2626
import _exportEventToFiles from './export-event-to-files.mjs';
27-
import _exportW3CMap from './export-w3cid-map.mjs';
2827
import _applySchedule from './apply-schedule.mjs';
2928

3029
function main() { _createOnOpenTrigger(); }
@@ -37,5 +36,4 @@ function importSessions() { _importSessions(); }
3736
function importMetadata() { _importMetadata(); }
3837
function exportMetadata() { _exportMetadata(); }
3938
function exportEventToFiles() { _exportEventToFiles(); }
40-
function exportW3CMap() { _exportW3CMap(); }
4139
function applySchedule() { _applySchedule(); }

tools/common/project.mjs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,4 +655,26 @@ export async function saveSessionNote(session, note, project) {
655655
console.log(JSON.stringify(response, null, 2));
656656
throw new Error(`GraphQL error, could not record "Note" for session #${session.number}`);
657657
}
658+
}
659+
660+
661+
/**
662+
* Update the project's title and description on GitHub
663+
*/
664+
export async function exportProjectMetadata(project) {
665+
const description = serializeProjectMetadata(project.metadata);
666+
const response = await sendGraphQLRequest(`mutation {
667+
updateProjectV2(input: {
668+
clientMutationId: "mutatis mutandis",
669+
projectId: "${project.id}",
670+
shortDescription: "${description.replace(/"/g, '\\\"')}",
671+
title: "${project.title.replace(/"/g, '\\\"')}"
672+
}) {
673+
clientMutationId
674+
}
675+
}`);
676+
if (!response?.data?.updateProjectV2?.clientMutationId) {
677+
console.log(JSON.stringify(response, null, 2));
678+
throw new Error(`GraphQL error, could not update the project's title and description`);
679+
}
658680
}

0 commit comments

Comments
 (0)