Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Action to automatically create hack day discussion threads #801

Closed
mfisher87 opened this issue Sep 3, 2024 · 11 comments · Fixed by #914 or #917
Closed

Action to automatically create hack day discussion threads #801

mfisher87 opened this issue Sep 3, 2024 · 11 comments · Fixed by #914 or #917
Labels
impact: automation CI, CD, or other automation

Comments

@mfisher87
Copy link
Collaborator

We're currently making these manually:

#800

We should be able to set up their creation on a bi-weekly cron in GitHub Actions!

@mfisher87 mfisher87 added the impact: automation CI, CD, or other automation label Sep 3, 2024
@Sherwin-14
Copy link
Collaborator

Sherwin-14 commented Oct 23, 2024

@mfisher87 Hey Matt, I would like to take this up. But before that I wanted to ask you what level of proficiency would be required in github actions for handling this one. I have none as of now (😂) but is it something that can be handled with little knowledge of actions?

@chuckwondo
Copy link
Collaborator

@Sherwin-14, before taking on anything else, would you mind either finishing the outstanding work on #792 or request that somebody else finishes it?

@mfisher87
Copy link
Collaborator Author

When you're ready, I think this is a reasonable first GitHub Action workflow for a learner :) It needs two pieces: A "cron" trigger, which uses the Linux cron syntax to define how frequently the workflow repeats; and a step which posts to our GitHub discussions something like this.

@Sherwin-14
Copy link
Collaborator

@Sherwin-14, before taking on anything else, would you mind either finishing the outstanding work on #792 or request that somebody else finishes it?

I am working on that one it's taking a bit longer than I expected because of writing those unittests.

@Sherwin-14
Copy link
Collaborator

@mfisher87 Hey Matt, actions/github-script only supports the REST API which does not contain the function to create a discussion thread, however, the GraphQL API does but GitHub has no plans on integrating the GraphQL API into GitHub Actions. Also I found something that may solve the problem. The ones who created this are working at GitHub so maybe we can count on this solution. what do you think?

@mfisher87
Copy link
Collaborator Author

That looks like a good choice! Thanks for doing the research on this :)

@Sherwin-14
Copy link
Collaborator

Sherwin-14 commented Jan 4, 2025

Well.. That didn't work out very well 😅, looks like the action I mentioned is broken. I resorted to using github CLI's graphQL API. I also had problems getting the text from previous hackdays embedded correctly, so I wrote my own.

Here's how the workflow file looks:

name: Generate Discussion Thread for Hackdays

on:
  workflow_dispatch:

jobs:
  create-discussion-threads:
    runs-on: ubuntu-latest
    permissions:
      discussions: write
      contents: read

    steps:

      - name: Generate the Hackathon title
        run: |
          DATE=$(date --iso-8601 | sed 's|-|/|g')
          echo "DISCUSSION_TITLE=Hackathon $DATE" >> $GITHUB_ENV

      - name: Set the Hackathon description
        run: |
          echo "DISCUSSION_BODY=Reporting out on earthaccess hack days. Use the 'comment' button at the very bottom to send a message. Additionally, consider sending issues and PRs relevant to your work to help make the job of future readers easier. It is okay to duplicate information here! Use the reply feature to have a discussion under any comment. Enjoy!" >> $GITHUB_ENV
          

      - name: Create Discussions
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} 
          REPOSITORY_ID: \"R_kgDOL9OsOA\"
          CATEGORY_ID: \"DIC_kwDOL9OsOM4ClttG\"
        run: |
         gh api graphql -f query="
         mutation 
          {createDiscussion
            (
              input: 
                {
                repositoryId: ${{ env.REPOSITORY_ID }}, 
                categoryId: ${{ env.CATEGORY_ID }}, 
                body: \"${{ env.DISCUSSION_BODY }}\", 
                title: \"${{ env.DISCUSSION_TITLE }}\"
                }
            ) 
            {
              discussion {id}
            }
          }"

Thoughts?

@mfisher87
Copy link
Collaborator Author

I think it looks great! Nice work! What do you think of moving the literal quotes from the REPOSITORY_ID and CATEGORY_ID envvars and into the run key, following the pattern of the body and title keys?

I like that it's set up with workflow dispatch instead of cron, as there will be weeks (like the past holiday weeks) where we skip the hackathon.

@Sherwin-14
Copy link
Collaborator

Alright, Nice!

On another note, the repo id and category id i am using are from my fork, Could you provide me the repo and category id for main repo. I had used giscus for getting the id's.

@mfisher87
Copy link
Collaborator Author

mfisher87 commented Jan 5, 2025

Looks like repository ID is MDEwOlJlcG9zaXRvcnkzOTk4Njc1Mjk= and discussions category id is DIC_kwDOF9V-ic4CdYaN!

Strange that the repository ID I'm getting back is significantly different in length than the one you used in your test. I tested a few repositories and it looks like the structure of the ID has changed over time.

I used the GitHub CLI to query the GraphQL API:

$ gh api graphql -f query='
{
  repository(owner: "nsidc", name: "earthaccess") {
    id
    name
    discussionCategories(first: 10) {
      nodes {
        id
        name
      }
    }
  }
}'
{
  "data": {
    "repository": {
      "id": "MDEwOlJlcG9zaXRvcnkzOTk4Njc1Mjk=",
      "name": "earthaccess",
      "discussionCategories": {
        "nodes": [
          {
            "id": "DIC_kwDOF9V-ic4B_awC",
            "name": "Announcements"
          },
          {
            "id": "DIC_kwDOF9V-ic4B_awD",
            "name": "General"
          },
          {
            "id": "DIC_kwDOF9V-ic4CdYaN",
            "name": "Hack days"
          },
          {
            "id": "DIC_kwDOF9V-ic4B_awF",
            "name": "Ideas"
          },
          {
            "id": "DIC_kwDOF9V-ic4CNngd",
            "name": "Polls"
          },
          {
            "id": "DIC_kwDOF9V-ic4B_awE",
            "name": "Q\u0026A"
          },
          {
            "id": "DIC_kwDOF9V-ic4B_awG",
            "name": "Show and tell"
          }
        ]
      }
    }
  }
}

@mfisher87
Copy link
Collaborator Author

Awesome work on this, thank you @Sherwin-14 ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
impact: automation CI, CD, or other automation
Projects
Status: Done
3 participants