get AppScript Project scripts

185 views
Skip to first unread message

Philip Pappas

unread,
Jan 5, 2023, 2:57:32 PM1/5/23
to Google Apps Script Community
i am trying to get all scripts from an AppScript project in order to push them to github using Github API.
Any idea on the first part? getting all scripts from a project?
Here are some things i tried

// get content from a script as a string

function getScriptSourceCode() {

  const scriptname = "github"
  // i don't want to manually write the script name
  var content = ScriptApp.getResource(scriptname).getDataAsString();
 
  return content
}


// get AppScript Project

function getSciptsfromProject() {

  // Use MimeType enum to log the name of every Google Doc in the user's Drive.

  var docs = DriveApp.getFilesByType(MimeType.GOOGLE_APPS_SCRIPT);
  var mydoc;
  while (docs.hasNext()) {
    var doc = docs.next();
    if (doc.getName() == "MyAppScriptProject") {
      mydoc = doc
    }
  }
  var scriptid = mydoc.getId()

  // but how can i get all its scripts?

  Logger.log(mydoc)
  Logger.log(scriptid)

}

Bruce Mcpherson

unread,
Jan 5, 2023, 6:07:45 PM1/5/23
to google-apps-sc...@googlegroups.com
This might help. I use it to automatically push all my projects to GitHub (GitHub.com/brucemcpherson) when they get updated.


--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/0e204047-9162-42c0-8af9-74e60407cb64n%40googlegroups.com.

Andrew Roberts

unread,
Jan 6, 2023, 5:56:57 AM1/6/23
to google-apps-sc...@googlegroups.com

Philip Pappas

unread,
Jan 7, 2023, 5:15:57 PM1/7/23
to Google Apps Script Community
couldn't get my head around installing gasgit. Especially the part where i change the settings to customize my repo and token.
I thought i would import the library to Google app scripts and then use the functions but apparently i need to clone the repository? (but if i clone it then what happens with the Script ID i use to import it into GAS)
Sorry, my questions might have obvious answers to someone with more exprerience

i ended up installing clasp and downloading all scripts to a folders which syncs to github, but i would really like to understand how gasgit works.

Philip Pappas

unread,
Jan 7, 2023, 5:17:23 PM1/7/23
to Google Apps Script Community
i was looking into using the Chrome extension as well, but was a bit concerned about giving permissions to a privately developed add-on. doesn't feel quite safe to be honest

Bruce Mcpherson

unread,
Jan 8, 2023, 7:09:04 AM1/8/23
to google-apps-sc...@googlegroups.com
Hey Philip

Here's how I use it.

. All the scripts I want to share publicly (about 150 of them) are kept in a series of folders and sub folders on drive.
. Every now and then I run gasgit which checks to see which ones have been modified, or any dependencies have been modified since the last time. Any it finds are pushed to their respective repos along with any libraries they reference and it also automatically generates dependency documentation. 
. Any new repos required are created automatically.
. Set up gasgit by making a copy of the gasgit script, set the top folder where your public scripts are stored, get GitHub credentials and set them up for Goa, publish as a webapp and run it once to get the token generator going, then unpublish the webapp.
. Run triggerbatch from time to time to keep the repos update.

No need to run clasp or worry about tokens. Gasgit automatically extracts all the files directly from a script project to an area on drive you specify and pushes them to GitHub from there.



Reply all
Reply to author
Forward
0 new messages