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

Comment and triage with GitHub Script #5

Closed
github-learning-lab bot opened this issue Jan 19, 2021 · 4 comments
Closed

Comment and triage with GitHub Script #5

github-learning-lab bot opened this issue Jan 19, 2021 · 4 comments

Comments

@github-learning-lab
Copy link

Great job @kirillperesh

Now that your updates have been merged and we've triggered the workflow we should see our workflow begin helping us automate the triage of new issues.

Workflow not running? Click here for some troubleshooting.

Try the following troubleshooting steps:

  1. Click on the Actions tab to see the status of your workflow run. See Managing a workflow run on GitHub Help for more information.
  2. Edit your workflow file and look for errors in the linter built into the browser.
  3. Look for the workflow trigger and ensure you are performing an action that triggers that workflow.

If you need to make changes to your code, remove the main branch protection and merge your changes into the main branch.


I'll respond once your workflow has completed!

@github-learning-lab github-learning-lab bot mentioned this issue Jan 19, 2021
@github-actions
Copy link

🎉 You've created this issue comment using GitHub Script!!!

@github-actions github-actions bot added this to Triage Backlog in Learning Lab Project Board Jan 19, 2021
@github-learning-lab
Copy link
Author

Let's improve the workflow

@kirillperesh it looks like you workflow has completed! Let's take a look at the results!

We should be pretty familiar with the first portion of the workflow, it's the same as the first time it ran, and it just creates a comment whenever a new issue has been created.

The second portion may exactly be clear to you, but this issue was added to a project board that is present in this repository. Checkout the projects tab if you want to see that this issue has been added!

Multiple steps

One benefit of using actions is the ability to separate jobs into smaller units of work called steps. If we think about what our workflow is doing we can see that it makes more sense to have these two tasks take place across two steps.

As an added advantage, once we break the current workflow into multiple steps we can apply logic through expressions to them. This will let us create rules around when steps are allowed to run. Ultimately this allows us to optimize our workflow run!

Since GitHub Script is simply an action, breaking each unique task into a new step works just fine! We will do this in our next activity!

@github-learning-lab
Copy link
Author

Add steps for each action

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

  • Name each step so we can easily keep track of it in the actions tab
  • Use expressions to determine if a step should execute

⌨️ Activity: Add newly opened issue to project board

  1. Edit the current workflow .github/workflows/my-workflow.yml to have the following contents:

    name: Learning GitHub Script
    
    on:
      issues:
        types: [opened]
    
    jobs:
      comment:
        runs-on: ubuntu-latest
        steps:
        - name: Comment on new issue
          uses: actions/github-script@0.8.0
          with:
            github-token: ${{secrets.GITHUB_TOKEN}}
            script: |
                github.issues.createComment({
                issue_number: context.issue.number,
                owner: context.repo.owner,
                repo: context.repo.repo,
                body: "🎉 You've created this issue comment using GitHub Script!!!"
                })
    
        - 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: 12524419,
                content_id: context.payload.issue.id,
                content_type: "Issue"
                });
    
  2. Commit the workflow to a new branch.

  3. Create a pull request, I suggest the title Create better comments.

  4. Supply the pull request body content and click Create pull request.


I am waiting for you to create a new pull request before moving on.

I'll respond in the pull request you create

@github-learning-lab
Copy link
Author

A new pull request

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

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

No branches or pull requests

0 participants