Skip to main content

Querying GitHub Issues from Google App Script

I'm currently exploring different integrations that can be done between Google App Script and Git. This is part of a bigger attempt to integrate Git data into my project management system. I'll post more on that later. GitHub supports a number of very nice sub-systems. One of them is the GitHub Issues ticket tracking system. It's fairly robust and comes with GitHub - which means it's highly integrated out-of-the-box. Integration with Google's App Script is done via the fetchURL command and JSON object manipulation.  After a good bit of experimentation, I've settled on querying GitHub Issues with an "on open spreadsheet event" to avoid issues with Google's quota system. Essentially, Google prevents you from calling the fetchURL command more than X times (see the quota limits ) per day. That's not great if you have people actively working and changing data in a spreadsheet. Some of my other App Script routines are running thousands of times per d

From Excel VBA to Google App Script: Unit Tests

If you've been following along on my Excel VBA App Script journey (Part 1, Part 2), I'm converting my old Excel VBA scripts to Google App Scripts. I'm specifically focused on Excel to Sheets at the moment but the general process applies to other App Script development.

As I mentioned last time, once I figured out that you cannot use the integrated debugger without a wrapper routine, the next logical exercise was adding unit tests. The test wrapper is essentially ready to go as a unit test, it's just a question of how to formalize it a bit.

At it's most basic, we could convert the test wrapper to return a pass/fail result and be done with it, ala:
function test_myFx()
{
  Logger.log("Test")
  return myFx("U01",SpreadsheetApp.getActiveSheet().getRange(2,2).getValues())
}

function myFx(findStr, findRange)
{
//Do some work
}

converts to:

function test_myFx()
{
  Logger.log("Test")
  if (myFx("U01",SpreadsheetApp.getActiveSheet().getRange(2,2).getValues())=="U01") {return "PASS";}
else {return "FAIL"}
}

function myFx(findStr, findRange)
{
//Do some work
}

and then just call the function from your spreadsheet to determine if everything is working. The way I've implemented this is highly dependent on the spreadsheet. I originally implemented it this way so I could mimic the Spreadsheet input but for unit testing, it's better to convert to a fixed input rather than relying on SpreadsheetApp. The code then moves to:
function test_myFx()
{
  Logger.log("Test")
var arr = ["U01", "U02", "U03"];
  if (myFx("U01",arr)=="U01") {return "PASS";}
else {return "FAIL"}
}

function myFx(findStr, findRange)
{
//Do some work
}


A more formalized system would use a framework. One that's highly recommended is QUnitGS2. They have an excellent tutorial here. This can be boiled down to:
  1. Add QUnitGS2 library to your App Script as a library
  2. Create a test script (Test.gs) that's distinct from your code (Code.gs)
  3. Instantiate the unit test frame work and connect it to your code
  4. Publish the system as web app (accessible only to you)
  5. Execute the published web app and view the results
I won't repeat the detail from the tutorial. It's extremely easy to follow and has a lot of screen caps to help. I didn't find any additional detailed needed to implement the framework.

In the end, the QUnitGS2 framework brings the functionality of standardized unit tests to Google App Script development and helps with keeping large libraries function and error free. 

Happy bug free deployment!

Comments

Popular posts from this blog

SMTP Mail and Indy (again)

Having spent a lot of time recently working on a ping scanner using Indy, I noticed that there's a lot of questions still on using SMTP with Indy. Let me first say that I am not an Indy expert. I get along with it successfully but find I still have to research things frequently. With the disclaimer out of the way, we can get to the offering. A while back I wrote a handy little unit to simply send a mail message with or without attachments and with or without providing authentication. It even has support for OpenSSL. I use this unit in a number of applications and have seen it successfully send hundreds of e-mails without issue. I recently added support for threaded message sending to take advantage of the multi-core system I'm now running on. This code has had a few additions (like the logger) that I've gleaned over time from various newsgroup postings, but I didn't record the authors so let me credit the anonymous Internet authors who support Indy. It's really amaz

Detecting a virtualized environment

CubicDesign on delphi-talk.elists.org recently asked the question: "How do I know/detect if my software is running under Windows [or a virtual environment]?" Well, it turns out that it's a lot harder to tell than you would think. Apparently, the VM (VMware, Xen, Wine, etc.) doesn't really want you to be able to do this. At least not easily. For VMware, there is a decent little C routine called jerry.c that does the trick. Jerry actually uses a simple communication channel that VMware left open. It's not 100% foolproof since the admin can change the channel, but that's not likely going to happen unless the system is specifically designed to be a honeypot. If you're running on a honeypot and still have a legitimate reason for detection, you could look at the much more complex scoopy implementation which inspects how the system is actually virtualized using the SIDT CPU instruction instead of a communication channel. Another reference (red pill) is here . F

Vista UAC Manifest

Here's a couple of interesting little tidbits for those using Delphi 2007 and trying to create manifest files to require your program to run as Administrator. For those who don't know what this means, we're talking about running a program and receiving the wonderful little pop-up "A program is trying to take over your life"... well, something like that anyway. You will need your program to receive elevated privileges if you want to do certain things. In my particular instance, I wanted to write to the HKEY_CLASSES_ROOT registry entries. This isn't supposed to be a full reference to what a manifest is, how it works, etc., etc. Microsoft has documented the UAC in some depth and I recommend using their documentation if you want to really understand your options. First, the manifest structure is basically just an XML document that tells Vista how it should handle the program. For elevated privileges, it should look like: < assembly xmlns ="urn:schemas-mic

Copyright 2008-2022, Marshall Fryman