website
website copied to clipboard
Create JSON file and related functionality for replacing hard-coded labels 5205
Fixes #5205
What changes did you make?
- Created the JSON file with key/value pairs for all repo labels-
label-directory.json
and located it in a new subfolder - Populated the JSON file with data extracted from the HfLA repo for all label names + ids (the directory Values) and generated Key camelCased names
- Wrote
retrieve-label-directory.js
that returns the actual label display name value when a label key name is provided - Wrote GHA
update-label-directory.yml
that is triggered whenever one of the HfLA labels is edited or is added. - Wrote a companion
update-label-directory.js
that determines whether the label is a name-change (such as by adding an emoji) or is a new label, then adds this change to the 'label directory' JSON, - In order to commit the changes to the repo, the GHA finishes with the
stefanzweifel/[email protected]
Why did you make the changes (we will use this info to test)?
- This series of issues was triggered by the study of adding emoji's to issue labels.
- We determined that we want the freedom to make changes to the labels without the need to track down all instances of each label being used. The intent of the 'label directory' is to be able to refer to a key label such as '2WeeksInactive' and return the actual label name
2 weeks inactive!!!
or💤 2 weeks inactive
or however we want to change the label, however many times.
Screenshots of Proposed Changes Of The Website (if any, please do not screen shot code changes)
-
Create label: Log file from personal repo showing label creation
Create label
-
Edit label: Log file from personal repo showing label editing
Edit label
-
Delete label: Log file from personal repo showing label deletion
Delete label
Notes to PR Reviewers
-
You will need to have a functioning test environment on your local repo. If you have not done this yet, see Hack for LA's GitHub Actions to set up, especially Tips 6 & 7. GHAs are quirky at first so feel free to ask questions.
-
In addition to the 'files changed' in the PR, there are additional changes that you should make to help with testing:
-
In the
update-label-directory.yml
file:- Line 11, redirect to your personal repo.
- Line 24, the "github-token" needs to be associated with your repo.
-
Note that none of the labels in the
label-directory.json
file will match your repo- this is OK.
-
-
To test this action, you can first create a new label. Go to "Issues" in your repo***, select "New Issue", and choose "Get Started" for any of the templates. Then on the right hand side select the gear icon for "Labels", then select "Edit labels" at the bottom, and finally "New label" to the upper right. Name the issue anything you want, but it might be easier to create a label beginning with an "a", eg.
A new label
or whatever. "Description" and "Color" can be anything you want. Select "Create label" and confirm your label is shown on the "Labels" page. -
(*** If you don't see "Issues" as a menu option, go to "Settings" and scroll down about halfway. Under "Features", make sure to check the box for "Issues".)
-
When you see that the label is created:
- Confirm that GitHub Actions was triggered: select "Actions", then check that a workflow named "Update Label Directory" has run. Feel free to explore the log...
- Confirm that your new label was added to
/_data/label-directory.json
. If your label starts with an "a", the JSON should be alphabetical.
-
Repeat the above steps to return to "Edit labels", select your new label, then make some change to the name. Add an emoji if you want. Confirm in that "Actions" has run and that the JSON file was updated.
-
Finally, repeat the above steps to delete the label, and confirm in "Actions" and the JSON file.
-
Want to review this pull request? Take a look at this documentation for a step by step guide!
From your project repository, check out a new branch and test the changes.
git checkout -b t-will-gillis-create-json-label-directory-5205 gh-pages
git pull https://github.com/t-will-gillis/website.git create-json-label-directory-5205
Note that CONTRIBUTING.md cannot previewed locally; rather it should be previewed at this URL:
https://github.com/t-will-gillis/website/blob/create-json-label-directory-5205/CONTRIBUTING.md
@marioantonini I connected with Will about this issue and it looks like it's still in draft, so I'm going to remove us as reviewers for now.
Also leaving this as a note to anyone else who sees this PR and considers picking it up.
Hello, I am having issues testing. I added the following ` name: Update Label Directory
on: label: types: [edited, created, deleted]
jobs: Update-Label-Directory: runs-on: ubuntu-latest # if: github.repository == 'hackforla/website' << FIX BEFORE MERGING. FIX URL line 40 BELOW if: github.repository == 'mSharifHub/website' steps: - uses: actions/checkout@v4 with: token: ${{ secrets.HFLA_PROJECT_BOARD_TOKEN }}
- name: Dump context
env:
GITHUB_CONTEXT: ${{ secrets.HFLA_PROJECT_BOARD_TOKEN }}
run: echo "GITHUB_CONTEXT defined"
- name: Update label directory
id: update-label-directory
uses: actions/github-script@v7
with:
github-token: ${{ secrets.HFLA_PROJECT_BOARD_TOKEN }}
script: |
const script = require('./github-actions/utils/update-label-directory.js')
const labelPacket = script({g: github, c: context})
return labelPacket
# Note the the URL below matches the *current* deployment URL of the Apps Script associated
# with the 'Source of Truth' Label spreadsheet. (If something is broken, check this link first)
- name: Send POST request to Google Apps Script
if: steps.update-label-directory.outputs.result != ''
run: |
curl -X POST "https://script.google.com/macros/s/AKfycbyZksNnRWXB6zSJn5QwaPjHPg27NFAzZM6GSpGBb2hkgk09E68LBBZVcdQ2EUVmPjfF/exec" \
-H "Content-Type: application/json" \
-d '${{ steps.update-label-directory.outputs.result }}'
# Before next step, run `git pull` so that branch is current
- name: Pull latest changes from gh-pages
run: git pull
- name: Commit changes to JSON Label Directory
uses: stefanzweifel/[email protected]
with:
# Glob pattern of file to commit, and opt. commit message + author
file_pattern: github-actions/utils/_data/label-directory.json
commit_message: Update label directory
commit_author: GitHub Actions Bot <[email protected]>
`
I then created a label but no actions were triggered.
if you can further explain more how to test it
Hi @mSharifHub Thanks for the comment.
Were you able to copy the new Project Board? I see that you have a message in the Slack channel asking about an error that occurred while you were setting it up. As long as the column names copy over, you should be OK and we can deal with "PR added to project" workflow omission separately.
I am looking at your test-5205
repo and have a couple of comments:
- I don't see that you have "Issues" enabled in your repo. If you haven't yet, go to "Settings" (last menu item at top right of your repo page), then scroll midway down and click "Issues".
- I can't see but assuming that you created your "HFLA_PROJECT_BOARD_TOKEN"...
- One last thing, if you have not already, you will need to change your default branch to
test-5205
(if this is the correct one)
Once "Issues" is active, the automation should begin to run at least (and might fail still). Let me know if you get to this point and then we can discuss. Thanks!
Hi @mSharifHub Thanks for the comment.
Were you able to copy the new Project Board? I see that you have a message in the Slack channel asking about an error that occurred while you were setting it up. As long as the column names copy over, you should be OK and we can deal with "PR added to project" workflow omission separately.
I am looking at your
test-5205
repo and have a couple of comments:* I don't see that you have "Issues" enabled in your repo. If you haven't yet, go to "Settings" (last menu item at top right of your repo page), then scroll midway down and click "Issues". * I can't see but assuming that you created your "HFLA_PROJECT_BOARD_TOKEN"... * One last thing, if you have not already, you will need to change your default branch to `test-5205` (if this is the correct one)
Once "Issues" is active, the automation should begin to run at least (and might fail still). Let me know if you get to this point and then we can discuss. Thanks!
I was trying to review the PR before commenting. I have configured the token. I have created a branch from the review branch and created a label under that branch on git but did see actions being called.
Review ETA: 3 PM Thursday Availability: Monday-Thursday