Package: gistyc
gistycgistyc is a Python-based library that enables developers to create, update and delete their GitHub GISTs. CLI capabilities allow you to execute the routines from the shell and can be integrated into your project's CI/CD pipeline to automatically create or update your GISTs (e.g., via GitHub actions). Files are separated in GIST sections depending on the separation blocks.gistyc considers currently only Python files (.py ending) in a Spyder-like code block separation (code block separator: #%%)PrerequisitesPython 3.8 (recommendation: using a virtual environment)AGitHub Personal access tokenwith GIST access:Click on your personal account profile (top right)ClickSettingsOn the left menu bar go toDeveloper settingsand choosePersonal access tokensGenerate new tokenand write a name (note) of your token. The note does not affect the functionality, but choose a note that describes the purpose of the token e.g.,GIST_tokenSet a mark atgist(Create gists) and click onGenerate tokenat the bottom of the pageIMPORTANT: The displayed token appears only once. Copy it and store it in your GitHub project as a secret and / or locally as an environment variable.Installationpipinstallgistyc... or install it from the main branch of thisrepository. You can also download the entire repository to run the tests, download the CI/CD scripts etc.Python library callsPlease note: ./tests provides some examples that can be reproduced / applied.We assume:AUTH_TOKEN: is the GIST access tokenFILEPATH: is the absolute or relative path of a Python fileGIST_ID: ID of a GIST.Create a GIST# importimportgistyc# Initiate the GISTyc class with the auth tokengist_api=gistyc.GISTyc(auth_token=AUTH_TOKEN)# Create a GIST with the sample fileresponse_data=gist_api.create_gist(file_name=FILEPATH)Update a GISTUpdating a GIST requires either ONLY the FILEPATH or the FILEPATH AND a corresponding GIST ID, if the GIST repository contains file names that occur more than once. Hint: keep your GIST repository clean from same-name files!Update using ONLY the FILEPATH:# importimportgistyc# Initiate the GISTyc class with the auth tokengist_api=gistyc.GISTyc(auth_token=AUTH_TOKEN)# Update the GIST with the updated sample file (update is based on the file's name)response_update_data=gist_api.update_gist(file_name=FILEPATH)Update using the FILEPATH AND GIST ID:# importimportgistyc# Initiate the GISTyc class with the auth tokengist_api=gistyc.GISTyc(auth_token=AUTH_TOKEN)# Update the GIST based on the GISTs IDresponse_update_data=gist_api.update_gist(file_name=FILEPATH,gist_id=GIST_ID)Get GISTsPlease note: one can obtain a list of all GISTs via:# importimportgistyc# Initiate the GISTyc class with the auth tokengist_api=gistyc.GISTyc(auth_token=AUTH_TOKEN)# Get a list of GISTsgist_list=gist_api.get_gists()Delete a GISTDeletion using ONLY the FILEPATH# importimportgistyc# Initiate the GISTyc class with the auth tokengist_api=gistyc.GISTyc(auth_token=AUTH_TOKEN)# Delete the GIST, based on the GIST IDresponse_data=gist_api.delete_gist(file_name=FILEPATH)Deletion using ONLY the GIST ID# importimportgistyc# Initiate the GISTyc class with the auth tokengist_api=gistyc.GISTyc(auth_token=AUTH_TOKEN)# Delete the GIST, based on the GIST IDresponse_data=gist_api.delete_gist(gist_id=GIST_ID)CLIPlease note: ./tests provides some examples that can be reproduced / applied.We assume:AUTH_TOKEN: is the GIST access tokenFILEPATH: is the absolute or relative path of a Python fileGIST_ID: ID of a GISTDIRECTORY: A directory (with an arbitrary number of sub-directories) that contains Python filesCreate a GISTgistyc--create--auth-tokenAUTH_TOKEN--file-nameFILEPATHUpdate a GISTUpdate using ONLY the FILEPATH:gistyc--update--auth-tokenAUTH_TOKEN--file-nameFILEPATHUpdate using the FILEPATH AND GIST ID:gistyc--update--auth-tokenAUTH_TOKEN--file-nameFILEPATH--gist-idGIST_IDDelete a GISTDeletion using ONLY the FILEPATHgistyc--delete--auth-tokenAUTH_TOKEN--file-nameFILEPATHDeletion using ONLY the GIST IDgistyc--delete--auth-tokenAUTH_TOKEN--gist-idGIST_IDDirectory Create & UpdateA second gistyc CLI allows you to provide a directory as an input that recursively gets all Python files and creates or updates GISTs accordingly. Please Note: File names MUST be unique in GIST.gistyc_dir--auth-tokenAUTH_TOKEN--directoryDIRECTORYExampleExample Python files (in a directory) can be foundhere.The corresponding GISTs are embedded hereinafter:https://gist.github.com/ThomasAlbin/b18383a86cb4396a79a551a73330ce76https://gist.github.com/ThomasAlbin/caddb300ac663e60ae573b1117599fcc.GitHub Actions - CI/CDThe following YAML file is used by the gistyc repository to provide an example on how to use gistyc in a CI/CD pipeline. Example Python scripts are stored, added and edited in ./examples. Changes in this directory trigger the pipeline (only after a merge with the main branch).# CI/CD GitHub Action YAML file## This YAML file executes a gistyc create / update pipeline on all Python files# within the folder ./examples (after merging to the main branch)name:GIST CD on main branch and example directory change# Check if files have been pushed to ./exampleson:push:paths:-examples/**# Execute the gistyc create / update pipelinejobs:build:# Execute the pipeline only on changes on the main brancheif:github.ref == 'refs/heads/main'runs-on:ubuntu-lateststrategy:matrix:python-version:['3.8']# Steps:# - Checkout the branch & use Python# - Install gistyc# - Use gistyc_dir, authenticate and use the ./examples directory as an inputsteps:-uses:actions/checkout@v2-name:Set up Python ${{ matrix.python-version }}uses:actions/setup-python@v2with:python-version:${{ matrix.python-version }}-name:Install gistycrun:pip install gistyc-name:Use gistyc CLI on examples/**run:gistyc_dir --auth-token ${{ secrets.GIST_TOKEN }} --directory ./examples/Support & ContributionsIf you have requests, issues or ideas please use the GitHub Issues. Contributions are always welcome and should be provided via a Pull Request. Please note the strict coding standards and other guidelines. These standards are checked for all PRs and can be seenhere. Please note that all functions must contain a pytest.Direct messages to the author of gistyc are always welcome. Please useTwitter,RedditorMediumfor this purpose.Best,Thomas