stagraph / write-github-script

https://lab.github.com/githubtraining/github-actions:-using-github-script
MIT License
0 stars 0 forks source link

Create an issue comment with GitHub Script #3

Closed github-learning-lab[bot] closed 3 years ago

github-learning-lab[bot] commented 3 years ago

Look πŸ‘€ at you!

Super awesome job so far!

Do you remember what our workflow trigger was?

on:
  issues:
    types: [opened]

This means that every time an issue gets opened in this repository the GitHub Script you wrote will execute.

You should expect to see the result right here in this issue!

Workflow not running? Click here for some troubleshooting. Try the following troubleshooting steps: 1. Click on the [Actions tab](https://github.com/stagraph/write-github-script/actions) to see the status of your workflow run. See [Managing a workflow run](https://help.github.com/en/actions/configuring-and-managing-workflows/managing-a-workflow-run) on GitHub Help for more information. 1. Edit your [workflow file]( https://github.com/stagraph/write-github-script/edit/main/.github/workflows/my-workflow.yml) and look for errors in the linter built into the browser. 1. Look for the [workflow trigger](https://help.github.com/en/actions/reference/events-that-trigger-workflows) 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](https://github.com/stagraph/write-github-script/settings/branches) and merge your changes into the `main` branch.

I'll respond in this issue after your workflow runs!

stagraph commented 3 years ago

oij

github-learning-lab[bot] commented 3 years ago

{"action":"created","issue":{"url":"https://api.github.com/repos/stagraph/write-github-script/issues/3","repository_url":"https://api.github.com/repos/stagraph/write-github-script","labels_url":"https://api.github.com/repos/stagraph/write-github-script/issues/3/labels{/name}","comments_url":"https://api.github.com/repos/stagraph/write-github-script/issues/3/comments","events_url":"https://api.github.com/repos/stagraph/write-github-script/issues/3/events","html_url":"https://github.com/stagraph/write-github-script/issues/3","id":765691654,"node_id":"MDU6SXNzdWU3NjU2OTE2NTQ=","number":3,"title":"Create an issue comment with GitHub Script","user":{"login":"github-learning-lab[bot]","id":37936606,"node_id":"MDM6Qm90Mzc5MzY2MDY=","avatar_url":"https://avatars0.githubusercontent.com/in/10572?v=4","gravatar_id":"","url":"https://api.github.com/users/github-learning-lab%5Bbot%5D","html_url":"https://github.com/apps/github-learning-lab","followers_url":"https://api.github.com/users/github-learning-lab%5Bbot%5D/followers","following_url":"https://api.github.com/users/github-learning-lab%5Bbot%5D/following{/other_user}","gists_url":"https://api.github.com/users/github-learning-lab%5Bbot%5D/gists{/gist_id}","starred_url":"https://api.github.com/users/github-learning-lab%5Bbot%5D/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/github-learning-lab%5Bbot%5D/subscriptions","organizations_url":"https://api.github.com/users/github-learning-lab%5Bbot%5D/orgs","repos_url":"https://api.github.com/users/github-learning-lab%5Bbot%5D/repos","events_url":"https://api.github.com/users/github-learning-lab%5Bbot%5D/events{/privacy}","received_events_url":"https://api.github.com/users/github-learning-lab%5Bbot%5D/received_events","type":"Bot","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2020-12-13T23:02:00Z","updated_at":"2020-12-13T23:02:54Z","closed_at":null,"author_association":"NONE","active_lock_reason":null,"body":"## Look πŸ‘€ at you!\n\nSuper awesome job so far!\n\nDo you remember what our workflow trigger was?\n\nyaml\non:\n issues:\n types: [opened]\n\n\nThis means that every time an issue gets opened in this repository the GitHub Script you wrote will execute.\n\nYou should expect to see the result right here in this issue!\n\n

\n Workflow not running? Click here for some troubleshooting.\n\nTry the following troubleshooting steps:\n1. Click on the Actions tab to see the status of your workflow run. See Managing a workflow run on GitHub Help for more information.\n1. Edit your workflow file and look for errors in the linter built into the browser.\n1. Look for the workflow trigger and ensure you are performing an action that triggers that workflow.\n\nIf you need to make changes to your code, remove the main branch protection and merge your changes into the main branch.\n
\n\n---\n\nI'll respond in this issue after your workflow runs!\n","performed_via_github_app":null},"comment":{"url":"https://api.github.com/repos/stagraph/write-github-script/issues/comments/744083807","html_url":"https://github.com/stagraph/write-github-script/issues/3#issuecomment-744083807","issue_url":"https://api.github.com/repos/stagraph/write-github-script/issues/3","id":744083807,"node_id":"MDEyOklzc3VlQ29tbWVudDc0NDA4MzgwNw==","user":{"login":"stagraph","id":32488367,"node_id":"MDQ6VXNlcjMyNDg4MzY3","avatar_url":"https://avatars2.githubusercontent.com/u/32488367?v=4","gravatar_id":"","url":"https://api.github.com/users/stagraph","html_url":"https://github.com/stagraph","followers_url":"https://api.github.com/users/stagraph/followers","following_url":"https://api.github.com/users/stagraph/following{/other_user}","gists_url":"https://api.github.com/users/stagraph/gists{/gist_id}","starred_url":"https://api.github.com/users/stagraph/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stagraph/subscriptions","organizations_url":"https://api.github.com/users/stagraph/orgs","repos_url":"https://api.github.com/users/stagraph/repos","events_url":"https://api.github.com/users/stagraph/events{/privacy}","received_events_url":"https://api.github.com/users/stagraph/received_events","type":"User","site_admin":false},"created_at":"2020-12-13T23:02:54Z","updated_at":"2020-12-13T23:02:54Z","author_association":"OWNER","body":"oij","performed_via_github_app":null},"repository":{"id":321175965,"node_id":"MDEwOlJlcG9zaXRvcnkzMjExNzU5NjU=","name":"write-github-script","full_name":"stagraph/write-github-script","private":false,"owner":{"login":"stagraph","id":32488367,"node_id":"MDQ6VXNlcjMyNDg4MzY3","avatar_url":"https://avatars2.githubusercontent.com/u/32488367?v=4","gravatar_id":"","url":"https://api.github.com/users/stagraph","html_url":"https://github.com/stagraph","followers_url":"https://api.github.com/users/stagraph/followers","following_url":"https://api.github.com/users/stagraph/following{/other_user}","gists_url":"https://api.github.com/users/stagraph/gists{/gist_id}","starred_url":"https://api.github.com/users/stagraph/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stagraph/subscriptions","organizations_url":"https://api.github.com/users/stagraph/orgs","repos_url":"https://api.github.com/users/stagraph/repos","events_url":"https://api.github.com/users/stagraph/events{/privacy}","received_events_url":"https://api.github.com/users/stagraph/received_events","type":"User","site_admin":false},"html_url":"https://github.com/stagraph/write-github-script","description":null,"fork":false,"url":"https://api.github.com/repos/stagraph/write-github-script","forks_url":"https://api.github.com/repos/stagraph/write-github-script/forks","keys_url":"https://api.github.com/repos/stagraph/write-github-script/keys{/key_id}","collaborators_url":"https://api.github.com/repos/stagraph/write-github-script/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/stagraph/write-github-script/teams","hooks_url":"https://api.github.com/repos/stagraph/write-github-script/hooks","issue_events_url":"https://api.github.com/repos/stagraph/write-github-script/issues/events{/number}","events_url":"https://api.github.com/repos/stagraph/write-github-script/events","assignees_url":"https://api.github.com/repos/stagraph/write-github-script/assignees{/user}","branches_url":"https://api.github.com/repos/stagraph/write-github-script/branches{/branch}","tags_url":"https://api.github.com/repos/stagraph/write-github-script/tags","blobs_url":"https://api.github.com/repos/stagraph/write-github-script/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/stagraph/write-github-script/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/stagraph/write-github-script/git/refs{/sha}","trees_url":"https://api.github.com/repos/stagraph/write-github-script/git/trees{/sha}","statuses_url":"https://api.github.com/repos/stagraph/write-github-script/statuses/{sha}","languages_url":"https://api.github.com/repos/stagraph/write-github-script/languages","stargazers_url":"https://api.github.com/repos/stagraph/write-github-script/stargazers","contributors_url":"https://api.github.com/repos/stagraph/write-github-script/contributors","subscribers_url":"https://api.github.com/repos/stagraph/write-github-script/subscribers","subscription_url":"https://api.github.com/repos/stagraph/write-github-script/subscription","commits_url":"https://api.github.com/repos/stagraph/write-github-script/commits{/sha}","git_commits_url":"https://api.github.com/repos/stagraph/write-github-script/git/commits{/sha}","comments_url":"https://api.github.com/repos/stagraph/write-github-script/comments{/number}","issue_comment_url":"https://api.github.com/repos/stagraph/write-github-script/issues/comments{/number}","contents_url":"https://api.github.com/repos/stagraph/write-github-script/contents/{+path}","compare_url":"https://api.github.com/repos/stagraph/write-github-script/compare/{base}...{head}","merges_url":"https://api.github.com/repos/stagraph/write-github-script/merges","archive_url":"https://api.github.com/repos/stagraph/write-github-script/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/stagraph/write-github-script/downloads","issues_url":"https://api.github.com/repos/stagraph/write-github-script/issues{/number}","pulls_url":"https://api.github.com/repos/stagraph/write-github-script/pulls{/number}","milestones_url":"https://api.github.com/repos/stagraph/write-github-script/milestones{/number}","notifications_url":"https://api.github.com/repos/stagraph/write-github-script/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/stagraph/write-github-script/labels{/name}","releases_url":"https://api.github.com/repos/stagraph/write-github-script/releases{/id}","deployments_url":"https://api.github.com/repos/stagraph/write-github-script/deployments","created_at":"2020-12-13T22:47:35Z","updated_at":"2020-12-13T23:02:02Z","pushed_at":"2020-12-13T23:02:00Z","git_url":"git://github.com/stagraph/write-github-script.git","ssh_url":"git@github.com:stagraph/write-github-script.git","clone_url":"https://github.com/stagraph/write-github-script.git","svn_url":"https://github.com/stagraph/write-github-script","homepage":"https://lab.github.com/githubtraining/github-actions:-using-github-script","size":0,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":1,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":0,"open_issues":1,"watchers":0,"default_branch":"main"},"sender":{"login":"stagraph","id":32488367,"node_id":"MDQ6VXNlcjMyNDg4MzY3","avatar_url":"https://avatars2.githubusercontent.com/u/32488367?v=4","gravatar_id":"","url":"https://api.github.com/users/stagraph","html_url":"https://github.com/stagraph","followers_url":"https://api.github.com/users/stagraph/followers","following_url":"https://api.github.com/users/stagraph/following{/other_user}","gists_url":"https://api.github.com/users/stagraph/gists{/gist_id}","starred_url":"https://api.github.com/users/stagraph/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stagraph/subscriptions","organizations_url":"https://api.github.com/users/stagraph/orgs","repos_url":"https://api.github.com/users/stagraph/repos","events_url":"https://api.github.com/users/stagraph/events{/privacy}","received_events_url":"https://api.github.com/users/stagraph/received_events","type":"User","site_admin":false},"installation":{"id":13387729,"node_id":"MDIzOkludGVncmF0aW9uSW5zdGFsbGF0aW9uMTMzODc3Mjk="}}

github-actions[bot] commented 3 years ago

πŸŽ‰ You've created this issue comment using GitHub Script!!!

github-learning-lab[bot] commented 3 years ago

Success πŸŽ‰!!!

@stagraph you're doing great! You've just used GitHub Script to comment on this issue!

Why might this be useful?

Using GitHub Actions can really help automate the events that take place in your repositories. Imagine it was a repository visitor who opened a new issue containing information about a critical bug. I assume you'd want to thank them for bringing that to your attention, however this simple task can become overwhelming as your repository attracts more visitors. By automating an issue comment we could easily thank our visitors every single time without the overhead of doing it manually.

What about us?

For the rest of the course we are going to design a workflow that helps us move issues into a GitHub Project board when they are created. This will give us increased visibility on the work that needs triage!

github-learning-lab[bot] commented 3 years ago

Let's add a card to a project board

We have added a project board to this repository for you. We will use this board, named Learning Lab Project Board, to add cards to when a new issue is created in your repository!

Like creating comments and opening pull requests, octokit/rest.js can be used for many more types of interactions. Managing GitHub Projects makes that list!

Things aren't always as they appear!
Although this is not a course on octokit/rest.js, it is important to tell you a little secret right here before we move on. For you to be able to use the `projects.createCard()` method there were some pieces of information we needed beforehand. Things like the `column_id` so we know which column to add the card to and even a `project_id` so we know which board that column belongs to. We've gone ahead and done this on our end of things so that we could give you the final piece to the puzzle and demonstrate how to use GitHub Script. So if you try to recreate this on your own, without the help of Learning Lab you will need to get that information and parse it in a way that works well for your use case!

:keyboard: 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:
       - 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!!!"
               })
               github.projects.createCard({
               column_id: 12074575,
               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 Add issues to project board.

  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 new pull request when I detect it has been created.

github-learning-lab[bot] commented 3 years ago

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.