Git Product home page Git Product logo

github-management-scripts's Introduction

GitHub Management Scripts

Keep track of your GitHub Profile and Organizations


Running on AWS, triggered by daily scheduled events,
this project fetches data about the viewer's GitHub Profile and selected Organizations,
compares them to the data stored from the previous run, and emails a diffs report.

  sequenceDiagram
    autonumber
    loop daily
      EventBridge->>Lambda: launches a daily scheduled event
    end
    Lambda->>GitHub: fetches data for creating reports
    Lambda->>S3: fetches previous stored reports
    opt if found diffs
      Lambda-->>S3: store the new reports
      Lambda-->>SES: send an email with a diffs report
    end

Environment variables

The following environment variables are required for runtime:

GITHUB_PAT="your-github-personal-access-token-goes-here"
S3_BUCKET_NAME="name-of-s3-bucket-goes-here"
ORGS_LIST="org-name,another-org-name"
EMAIL_RECIPIENT="email-to-send-notification-to-goes-here"
EMAIL_SENDER="email-to-send-mails-from-goes-here"
Token scopes

  • repo
  • read:packages
  • admin:org
  • read:user
  • read:discussion
  • read:project

Additional environment variables

These, are probably being handled by your local aws-cli or Lambda environment,
nevertheless, if you're running this app without Lambda, you need to set these manually:

AWS_ACCESS_KEY_ID="iam-user-access-key-id-goes-here"
AWS_SECRET_ACCESS_KEY="iam-user-secret-access-key-goes-here"
AWS_REGION="aws-region-goes-here"

Deployment instructions

AWS services used for this project are:

AWS IAM

  • Create a service user and attach the AWSLambda_FullAccess permissions policy to it, take note of the new user's access key id and secret access key. We'll use this user's credentials to deploy Lambda function from the CI workflows.
  • Create a Role and attach the following policies to it, AWSLambdaExecute which includes permission to CloudWatch and S3, and the AmazonSESFullAccess (full access is mandatory). We will use this for our Lambda execution for allowing our function to access the rest of the services.

AWS S3

  • Create a bucket for storing the previous reports for comparison, it doesn't have to be a public accessible one. and it's up to you if you want to make it preserve versions.

AWS SES

  • Configure based on the given instructions, as you see fit, i.e. verify your custom domain and custom from domain if needed.
    Make sure to take you service out of the sandbox environment if you want to able to properly send emails.

AWS Lambda

  • Create a function based on the execution IAM Role you created earlier.
  • Set the handler to src/main.handler
  • Set the timeout to at least a minute, depending on how many items you are fetching.
  • Build the project with npm ci
  • Upload a Zip archive containing at the following:
    • src/
    • node_modules/
    zip -r github-management-scripts.zip src/ node_modules/
  • Publish a new version.
  • Create an alias named Live and point it to published version, this will help us maintain versioning for your function, as the triggering event will invoke this alias.
    Note, I like also creating a Dev alias that I use while staging, you can take a look at this project's CI workflows.
  • Create the following environment variables for the function's context.
    Note that AWS connection-related variables are being handled by Lambda:
    • GITHUB_PAT token scopes: repo, read:packages, admin:org, read:user, read:discussion, read:project
    • S3_BUCKET_NAME the name of the bucket you created
    • ORGS_LIST comma separated list of organizations you want to track.
    • EMAIL_RECIPIENT where to send the diffs to.
    • EMAIL_SENDER sender email for the diffs email.

Note, this section is hit twice, come back here after the creating the event rule.

AWS CloudWatch

  • After the first function invocation, a designated log group will be created, the default retention for it will be *Never Expires*, you can reduce it, 1 week should suffice.

AWS EventBridge

  • Create a scheduled rule, for instance 0-10-*-*-?-* will run daily at 10AM.
    Set it to invoke your recently created Lambda function, and select Live as the alias.
    Get back to the Lambda function, and select the new EventBridge rule you created as th trigger.

Run locally
  • Create a file named .env at the project's root with the required environment variables
  • Install all dependencies with npm install
  • Run the application with npm run start:dev

github-management-scripts's People

Contributors

dependabot[bot] avatar tomerfi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.