From c46610ac1883462ea67dd7b0099ffa2d5d1a6b97 Mon Sep 17 00:00:00 2001 From: DHARMIK GANGANI Date: Sat, 7 Dec 2024 16:39:05 -0400 Subject: [PATCH 1/4] Update main.yml --- .github/workflows/main.yml | 89 +++++++++++++++----------------------- 1 file changed, 35 insertions(+), 54 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 75b6adf..1564bbb 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,61 +1,42 @@ -name: Track External Repository Issues +name: Fetch Issues and Send Notifications -#on: - # schedule: - # - cron: "*/1440 * * * *" # Run every 15 minutes - #workflow_dispatch: # Allows you to trigger the workflow manually +on: + schedule: + # Runs the workflow every 2 hours + - cron: "0 */2 * * *" -#jobs: - # track-issues: - # runs-on: ubuntu-latest + workflow_dispatch: # Allows manual trigger of the workflow -# steps: - # - name: Query Issues from External Repo - # env: - # GITHUB_PAT: ${{ secrets.GITH_TOKEN }} - # TARGET_OWNER: "Dharma-09" # Replace with the owner of the repo you want to track - # TARGET_REPO: "Arjun" # Replace with the repo name - # LABEL: "good-first-issue" # Replace with the label you want to track - #run: | - # GraphQL query to fetch issues - # QUERY='{ - # "query": "query($owner: String!, $repo: String!, $label: String!) { - # repository(owner: $owner, name: $repo) { - # issues(first: 10, labels: [$label], states: OPEN) { - # edges { - # node { - # title - # url - # createdAt - # author { - # login - } - } - } - } - } - }", - "variables": { - "owner": "'"$TARGET_OWNER"'", - "repo": "'"$TARGET_REPO"'", - "label": "'"$LABEL"'" - } - }' +jobs: + fetch-issues: + runs-on: ubuntu-latest - # Call GitHub GraphQL API - RESPONSE=$(curl -s -X POST -H "Authorization: Bearer $GITH_TOKEN" \ - -H "Content-Type: application/json" \ - -d "$QUERY" \ - https://api.github.com/graphql) + steps: + # Step 1: Checkout the repository + - name: Checkout code + uses: actions/checkout@v4 - echo "GraphQL Response: $RESPONSE" + # Step 2: Set up Go + - name: Setup Go + uses: actions/setup-go@v4 + with: + go-version: 1.20 - # Extract and format issues - ISSUES=$(echo "$RESPONSE" | jq -r '.data.repository.issues.edges[] | "Title: \(.node.title)\nURL: \(.node.url)\nAuthor: \(.node.author.login)\nCreated: \(.node.createdAt)\n"') + # Step 3: Install Dependencies + - name: Install dependencies + run: go mod tidy - if [ -z "$ISSUES" ]; then - echo "No new issues found with label '$LABEL' in $TARGET_OWNER/$TARGET_REPO." - else - echo -e "New Issues:\n$ISSUES" - # You can add a step here to send notifications (Slack, email, etc.) - fi + # Step 4: Run the Go application + - name: Fetch Issues and Send Notifications + env: + GIT_TOKEN: ${{ secrets.GIT_TOKEN }} # Token for GitHub GraphQL API + EMAIL_USERNAME: ${{ secrets.EMAIL_USERNAME }} # Email account username + WPRD_MAIL: ${{ secrets.WPRD_MAIL }} # Email account app password + SMTP_SERVER: "smtp.gmail.com" # Change for your email provider + SMTP_PORT: "587" # SMTP Port + REPO_OWNER: "kubevirt" # Replace with target repo owner + REPO_NAME: "kubevirt" # Replace with target repo name + LABEL: "good-first-issue" # Replace with the desired label + RECEIVER_EMAIL: "receiver@example.com" # Replace with recipient email + run: | + go run main.go From 67a61d64ef3c250fd40ddbc9d2b4f6c8244f7ded Mon Sep 17 00:00:00 2001 From: DHARMIK GANGANI Date: Sat, 7 Dec 2024 16:40:16 -0400 Subject: [PATCH 2/4] Update main.yml --- .github/workflows/main.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1564bbb..3ab28e7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -34,9 +34,9 @@ jobs: WPRD_MAIL: ${{ secrets.WPRD_MAIL }} # Email account app password SMTP_SERVER: "smtp.gmail.com" # Change for your email provider SMTP_PORT: "587" # SMTP Port - REPO_OWNER: "kubevirt" # Replace with target repo owner - REPO_NAME: "kubevirt" # Replace with target repo name + REPO_OWNER: "Dharma-09" # Replace with target repo owner + REPO_NAME: "CI-CD-pipelines-examples" # Replace with target repo name LABEL: "good-first-issue" # Replace with the desired label - RECEIVER_EMAIL: "receiver@example.com" # Replace with recipient email + RECEIVER_EMAIL: "dharmik.gangani17@gmail.com" # Replace with recipient email run: | go run main.go From 8ade920a7a84932863aa26dad5d6a9f0ccd69c2b Mon Sep 17 00:00:00 2001 From: DHARMIK GANGANI Date: Sat, 7 Dec 2024 16:43:29 -0400 Subject: [PATCH 3/4] Update main.yml Now code will fetch issue every five minute --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3ab28e7..a8903f7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -3,7 +3,7 @@ name: Fetch Issues and Send Notifications on: schedule: # Runs the workflow every 2 hours - - cron: "0 */2 * * *" + - cron: "*/5 * * * *" workflow_dispatch: # Allows manual trigger of the workflow From 68545c03193d45aa9bdcc36b38e07f6f0f6ee36a Mon Sep 17 00:00:00 2001 From: DHARMIK GANGANI Date: Sat, 7 Dec 2024 16:48:51 -0400 Subject: [PATCH 4/4] Update main.go --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index e66128e..d6885b8 100644 --- a/main.go +++ b/main.go @@ -58,7 +58,7 @@ func loadConfig() Config { } config := Config{ - GithubToken: os.Getenv("GITHUB_TOKEN"), + GithubToken: os.Getenv("GIT_TOKEN"), RepoOwner: os.Getenv("TARGET_REPO_OWNER"), RepoName: os.Getenv("TARGET_REPO_NAME"), Label: os.Getenv("LABEL_TO_TRACK"),