Skip to content

Commit

Permalink
Drop "Associate with repo" custom menu
Browse files Browse the repository at this point in the history
The repository name is now read from the "Event" sheet.
  • Loading branch information
tidoust committed Jan 8, 2025
1 parent 0326c34 commit 073963e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 39 deletions.
1 change: 0 additions & 1 deletion tools/appscript/add-custom-menu.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
30 changes: 17 additions & 13 deletions tools/appscript/import-from-github.mjs
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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) {
Expand Down
23 changes: 0 additions & 23 deletions tools/appscript/link-to-repository.mjs

This file was deleted.

2 changes: 0 additions & 2 deletions tools/appscript/main.mjs
Original file line number Diff line number Diff line change
@@ -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(); }

0 comments on commit 073963e

Please sign in to comment.