From 073963e9cdbd9d5c8229c7f52c6811ca6bf87df6 Mon Sep 17 00:00:00 2001 From: Francois Daoust Date: Wed, 8 Jan 2025 11:27:07 +0100 Subject: [PATCH] Drop "Associate with repo" custom menu The repository name is now read from the "Event" sheet. --- tools/appscript/add-custom-menu.mjs | 1 - tools/appscript/import-from-github.mjs | 30 +++++++++++++++----------- tools/appscript/link-to-repository.mjs | 23 -------------------- tools/appscript/main.mjs | 2 -- 4 files changed, 17 insertions(+), 39 deletions(-) delete mode 100644 tools/appscript/link-to-repository.mjs diff --git a/tools/appscript/add-custom-menu.mjs b/tools/appscript/add-custom-menu.mjs index 47fb17a..56789aa 100644 --- a/tools/appscript/add-custom-menu.mjs +++ b/tools/appscript/add-custom-menu.mjs @@ -6,7 +6,6 @@ export default function () { SpreadsheetApp.getUi().createMenu('TPAC') .addItem('Export event data as JSON', 'exportEventData') - .addItem('Associate with GitHub repository', 'associateWithGitHubRepository') .addItem('Import data from GitHub', 'importFromGithub') .addItem('Generate grid', 'generateGrid') .addToUi(); diff --git a/tools/appscript/import-from-github.mjs b/tools/appscript/import-from-github.mjs index 8a4d7d3..7b63f3b 100644 --- a/tools/appscript/import-from-github.mjs +++ b/tools/appscript/import-from-github.mjs @@ -1,22 +1,26 @@ -import associateWithGitHubRepository from './link-to-repository.mjs'; +import { getProject } from './project.mjs'; import reportError from './report-error.mjs'; /** * Trigger a GitHub workflow that refreshes the data from GitHub */ export default function () { - const scriptProperties = PropertiesService.getScriptProperties(); - const GITHUB_TOKEN = scriptProperties.getProperty('GITHUB_TOKEN'); - const spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); - let repository = spreadsheet.getDeveloperMetadata().find(data => data.getKey() === 'repository'); - if (!repository) { - associateWithGitHubRepository(); - repository = spreadsheet.getDeveloperMetadata().find(data => data.getKey() === 'repository'); - if (!repository) { - return; - } + const project = getProject(SpreadsheetApp.getActiveSpreadsheet()); + + if (!project.metadata.reponame) { + reportError(`No GitHub repository associated with the current document. + +Make sure that the "GitHub repository name" parameter is set in the "Event" sheet. + +Also make sure the targeted repository and project have been properly initialized. +If not, ask François or Ian to run the required initialization steps.`); } - const repo = repository.getValue(); + + const repoparts = project.metadata.reponame.split('/'); + const repo = { + owner: repoparts.length > 1 ? repoparts[0] : 'w3c', + name: repoparts.length > 1 ? repoparts[1] : repoparts[0] + }; const options = { method : 'post', @@ -34,7 +38,7 @@ export default function () { }; const response = UrlFetchApp.fetch( - `https://api.github.com/repos/${repo}/actions/workflows/sync-spreadsheet.yml/dispatches`, + `https://api.github.com/repos/${repo.owner}/${repo.name}/actions/workflows/sync-spreadsheet.yml/dispatches`, options); const status = response.getResponseCode(); if (status === 200 || status === 204) { diff --git a/tools/appscript/link-to-repository.mjs b/tools/appscript/link-to-repository.mjs deleted file mode 100644 index b8d1b89..0000000 --- a/tools/appscript/link-to-repository.mjs +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Associate with GitHub repository - */ -export default function () { - const spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); - const repository = spreadsheet.getDeveloperMetadata().find(data => data.getKey() === 'repository'); - const msg = repository ? - `The spreadsheet is currently associated with the GitHub repository "${repository.getValue()}". -To change the association, please provide the new repository name below.` : - 'Please enter the GitHub repository that contains the TPAC/breakouts data, e.g. "w3c/tpac2024-breakouts".'; - const ui = SpreadsheetApp.getUi(); - const response = ui.prompt('Enter GitHub repository', msg, ui.ButtonSet.OK_CANCEL); - if (response.getSelectedButton() == ui.Button.OK) { - const value = response.getResponseText(); - // TODO: validate the entered repository somehow - if (repository) { - repository.setValue(value); - } - else { - spreadsheet.addDeveloperMetadata('repository', value); - } - } -} \ No newline at end of file diff --git a/tools/appscript/main.mjs b/tools/appscript/main.mjs index 3cbf02b..3a07175 100644 --- a/tools/appscript/main.mjs +++ b/tools/appscript/main.mjs @@ -1,13 +1,11 @@ import _createOnOpenTrigger from './create-onopen-trigger.mjs'; import _addTPACMenu from './add-custom-menu.mjs'; -import _associateWithGitHubRepository from './link-to-repository.mjs'; import _importFromGitHub from './import-from-github.mjs'; import _generateGrid from './generate-grid.mjs'; import _exportEventData from './export-event-data.mjs'; function main() { _createOnOpenTrigger(); } function addTPACMenu() { _addTPACMenu(); } -function associateWithGitHubRepository() { _associateWithGitHubRepository(); } function importFromGitHub() { _importFromGitHub(); } function generateGrid() { _generateGrid(); } function exportEventData() { _exportEventData(); }