Action to automatically create hack day discussion threads
We're currently making these manually:
https://github.com/nsidc/earthaccess/discussions/800
We should be able to set up their creation on a bi-weekly cron in GitHub Actions!
@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?
@Sherwin-14, before taking on anything else, would you mind either finishing the outstanding work on https://github.com/nsidc/earthaccess/pull/792 or request that somebody else finishes it?
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, 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.
@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?
That looks like a good choice! Thanks for doing the research on this :)
Well.. That didn't work out very well :sweat_smile:, 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?
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.
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.
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"
}
]
}
}
}
}
Awesome work on this, thank you @Sherwin-14 :heart: