Git Versioning – Python Script

Prev Next

Introduction

This Git versioning script is built to automate the updating of transaction scripts within Catchpoint. Once the latest version of a transaction script is updated in Git, we can execute the attached Python script. This will get the latest version of the transaction script from Git and update the corresponding transaction test in the Catchpoint portal.

Note: Script requires one-time configurations as described below.

Prerequisites

  • Python 3 needs to be installed.
  • Catchpoint API credentials and script details to be added in the script.

Configuration

Configuring the script

  1. Open the attached Python script in your preferred text editor.

  2. Configure Git repository details.
    git1.png

    • Edit creds_basic_CP dictionary as per your account details in Git.

      • domain is configured to fetch raw data from Git.
      • path should be modified with respective user, repo name, and branch name/master. This path should point at the file to be fetched from Git repo.
  3. Link Catchpoint and Git scripts.
    git2.png
    Edit script_links dictionary to link the scripts from Catchpoint and Git. The Python script will depend on this to update all the scripts. We need to provide the script id from Catchpoint with script name from Git. In the screenshot above, id 182823 from Catchpoint references to script1 in Git. Here we are working with two scripts; we can add any number of script references as per the requirements.

  4. Set up Catchpoint API credentials as environment variables.
    git3.png
    Catchpoint API key and secret should be set with environments names as shown in the screenshot above

Note: The attached script and the above configurations are tested with public Git repos. For private repose will need to add the Authentication header with Git API token.

Implementation

Run Python script

Once all the above configurations are complete, the Python script can be executed. During script execution, you will see the following prompts:

  1. Enter Script Name
    git4.png
  2. Confirm Script changes
    git5.png
  3. Success
    git6.png

How does Python script work?

  1. It downloads the Git script based on the configurations. During script execution, it will ask to type the script name. It will only download the specified script file.
  2. It generates an authentication token for communication with Catchpoint.
  3. It gets the current Catchpoint script details. This would include the script as well other script related information. It only modifies it to add the new scripts we got from Git.
  4. It sends the new script to back to Catchpoint.

Whenever you push an update to your script in Git, execute this script and provide the script name, and Catchpoint will be updated. This eliminates the need to login to the Catchpoint portal to perform the manual change.

Note

This script four Catchpoint REST API calls to update one script.

Git Versioning.py