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

Create better comments #8

Merged
merged 2 commits into from
Jun 8, 2022
Merged

Create better comments #8

merged 2 commits into from
Jun 8, 2022

Conversation

SuMineLee
Copy link
Owner

No description provided.

@github-learning-lab
Copy link

Improving the issue comment

💡Did you know that GitHub Script also grants you access to a full Node.js environment?

Although we wouldn't recommend using GitHub Script to write the logic for complex actions, there are use cases where you may want to leverage using a little more than just the octokit/rest.js API.

One such use case is our issue comment. Right now it is pretty hard coded the way it is making it less than ideal. What if we wanted to display our contribution guide every time an issue was opened?

Instead of writing the guide directly into our workflow, we can use the Node.js File System module to read a file and use it as the body of our issue comment.

If we want access to the files within our repository, we need to make sure we include the actions/checkout action in our workflow as the first step.

@github-learning-lab
Copy link

Use a comment template from the repository

We will make the following changes to the current workflow file:

  • Add the actions/checkout action so we can read the templated response file located at .github/ISSUE_RESPONSES/comment.md
  • Add JavaScript to use the Node.js File System module to place the contents of our templated response as the body of the issue comment.

⌨️ Activity: Use the FS module to use a templated comment

  1. Edit the current workflow to have the following contents:

    name: Learning GitHub Script
    
    on:
      issues:
        types: [opened]
    
    jobs:
      comment:
        runs-on: ubuntu-latest
        steps:
          - name: Checkout repo
            uses: actions/checkout@v2
    
          - name: Comment on new issue
            uses: actions/github-script@0.8.0
            with:
              github-token: ${{secrets.GITHUB_TOKEN}}
              script: |
                 const fs = require('fs')
                 const issueBody = fs.readFileSync(".github/ISSUE_RESPONSES/comment.md", "utf8")
                 github.issues.createComment({
                 issue_number: context.issue.number,
                 owner: context.repo.owner,
                 repo: context.repo.repo,
                 body: issueBody
                 })
    
          - name: Add issue to project board
            if: contains(github.event.issue.labels.*.name, 'bug')
            uses: actions/github-script@0.8.0
            with:
              github-token: ${{secrets.GITHUB_TOKEN}}
              script: |
                github.projects.createCard({
                column_id: 18868505,
                content_id: context.payload.issue.id,
                content_type: "Issue"
                });
    
  2. Commit the workflow changes to this branch.


I am waiting for you to commit the desired changes to this branch before moving on.

I'll respond once you've committed the changes to this branch

Copy link

@github-learning-lab github-learning-lab bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Time to see the magic in action!

@SuMineLee, All of the necessary changes have been made, and our workflow now contains enough information to be quite awesome!

⌨️ Activity: Merge the workflow

When you are ready, merge this pull request.


I am waiting for you to merge this pull request before moving on.

Once you have merged this pull request I will open a new issue so we can see this workflow in action!

Trouble merging?Try refreshing the page!

@SuMineLee SuMineLee merged commit b4b9c7d into main Jun 8, 2022
@github-learning-lab
Copy link

A new issue has been opened

I have created a new issue where we will continue this lesson. Click the link to meet me over there.

@github-learning-lab
Copy link

Whoo hoo 🎉

Super awesome job @SuMineLee! As you can see, your workflow still commented on this issue, but it did not add it to the project board!

Don't hesitate to experiment with changes to the current workflow to see if what kind of logic you can implement to change the response to an issue based on the conditions that surround your own software development lifecycle!

@github-learning-lab
Copy link

What you learned

As we wrap this course up it's important that we revisit the learning points you encountered along the way.

Things you learned in this course:

  • What GitHub Script is
  • How GitHub Script maps to octokit/rest.js
  • How to use the GitHub Script action in your workflow
    • By commenting when an issue is opened
    • By adding an issue to a project board when it is opened
  • How to read a file from the repository for use with GitHub Script
  • How to apply expressions to a workflow file

That should give you quite the start with incorporating the GitHub Script action into your workflows!


Congratulations on finishing this course. You will receive no further responses from me, however further action taken in this repo could trigger workflow runs, because of this we recommend commenting out the workflow file if you plan to keep this repository for notes!

@github-learning-lab
Copy link

Whoo hoo 🎉

Super awesome job @SuMineLee! As you can see, your workflow still commented on this issue, but it did not add it to the project board!

Don't hesitate to experiment with changes to the current workflow to see if what kind of logic you can implement to change the response to an issue based on the conditions that surround your own software development lifecycle!

@github-learning-lab
Copy link

What you learned

As we wrap this course up it's important that we revisit the learning points you encountered along the way.

Things you learned in this course:

  • What GitHub Script is
  • How GitHub Script maps to octokit/rest.js
  • How to use the GitHub Script action in your workflow
    • By commenting when an issue is opened
    • By adding an issue to a project board when it is opened
  • How to read a file from the repository for use with GitHub Script
  • How to apply expressions to a workflow file

That should give you quite the start with incorporating the GitHub Script action into your workflows!


Congratulations on finishing this course. You will receive no further responses from me, however further action taken in this repo could trigger workflow runs, because of this we recommend commenting out the workflow file if you plan to keep this repository for notes!

@github-learning-lab
Copy link

Whoo hoo 🎉

Super awesome job @SuMineLee! As you can see, your workflow still commented on this issue, but it did not add it to the project board!

Don't hesitate to experiment with changes to the current workflow to see if what kind of logic you can implement to change the response to an issue based on the conditions that surround your own software development lifecycle!

@github-learning-lab
Copy link

What you learned

As we wrap this course up it's important that we revisit the learning points you encountered along the way.

Things you learned in this course:

  • What GitHub Script is
  • How GitHub Script maps to octokit/rest.js
  • How to use the GitHub Script action in your workflow
    • By commenting when an issue is opened
    • By adding an issue to a project board when it is opened
  • How to read a file from the repository for use with GitHub Script
  • How to apply expressions to a workflow file

That should give you quite the start with incorporating the GitHub Script action into your workflows!


Congratulations on finishing this course. You will receive no further responses from me, however further action taken in this repo could trigger workflow runs, because of this we recommend commenting out the workflow file if you plan to keep this repository for notes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant