メインコンテンツにスキップ

ScriptHistoryApp

This is a Google Apps Script library for managing the histories of the Google Apps Script project.

AI Summary

ScriptHistoryApp

A library for saving, retrieving and restoring Google Apps Script project histories.

Target Users

Intermediate to advanced Google Apps Script developers who need fine-grained version management missing in the new IDE.

Problems Solved

The new GAS IDE only shows deployed versions; creating a deployment for every save is costly. Developers need a simple way to keep and roll back to any saved state.

Tags

Main Features

1
Automatic history on every save

Each time you save, the library stores the whole project to Drive through the Apps Script API, eliminating extra deployment steps.

2
Both HTML UI and script API

Manage, search and restore versions through a Web Apps UI or programmatically via HTTP requests from GAS code.

3
Automatic backup before restore

When rolling back, the current version is saved first, allowing safe undo of any restoration.

Usage Examples

Save the current script to history

// Minimal example that stores the current code to Drive via ScriptHistoryApp
function saveCurrentScript() {
  const webAppsUrl = "https://script.google.com/macros/s/###/dev"; // URL of the Web Apps linked to ScriptHistoryApp
  const folderId   = "###"; // Drive folder where history files are placed

  // Build query parameters
  const params = {
    scriptId: ScriptApp.getScriptId(), // GAS project to be recorded
    folderId,
    process : "store"                  // Tell the server to store a new history
  };
  const query = Object.keys(params)
    .map(k => `${k}=${encodeURIComponent(params[k])}`)
    .join("&");

  // Call the Web Apps endpoint with an OAuth2 bearer token
  const headers  = { authorization: "Bearer " + ScriptApp.getOAuthToken() };
  const response = UrlFetchApp.fetch(`${webAppsUrl}?${query}`, { headers });
  Logger.log(response.getContentText()); // e.g. "Save as 2023-10-01T01:23:45.000Z"
}

Add this function to your Client project and run it. The current script is stored in the designated Drive folder, and the ISO timestamp returned acts as the history ID for later look-ups or rollbacks.