Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
emmatown committed Oct 4, 2019
0 parents commit c9af076
Show file tree
Hide file tree
Showing 12 changed files with 5,020 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
46 changes: 46 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# @changesets/bot

## 1.1.5

### Patch Changes

- 6dbc7dc: Fix babel configs for building packages to produce working dists for node scripts.

## 1.1.4

### Patch Changes

- 88dd1b5: Refactored bot to combine endpoints and added unit tests

## 1.1.3

### Patch Changes

- 5e9ecdc: Fix spelling error
- 2ca59c0: Change deployment environment to staging

## 1.1.2

### Patch Changes

- a18dd18: Got feedback that our changeset messages could be a bit loud/scary. Here is some lighter, friendlier text

## 1.1.1

- [patch] fa74183:

- Link messages out to information on changesets

- [patch] a1d1b56:

- Display commit sha instead of commit message in bot comment

## 1.1.0

- [patch] f7a6395:

- Handle case where committer field in webhook event is null

- [minor] 9bd107d:

- Added new bot to detect changesets on PRs
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# changeset-bot

> A GitHub App built with [Probot](https://github.com/probot/probot) that Bot to detect changesets in PRs
## Setup

```sh
# Install dependencies
npm install

# Run the bot
npm start
```

## Installing in your repository

Install the bot from https://github.com/apps/changeset-bot and select the desired repository.

In your repository settings, add a new webhook with the following values.

- Payload URL - `https://smee.io/TNpTJ36TKInIWlgB`
- Content type - `application/json`
- Trigger events - `Pull requests`

## Behaviour

The changeset bot will listen for pull requests being opened and pull requests that have been updated, upon which it will
then scan through the files for a changeset that has been added. The bot will make a comment on the PR stating
whether it found a changeset or not, as well as the message of the latest commit. If the PR is being updated
then the bot will update the existing comment.
139 changes: 139 additions & 0 deletions app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
# This is a GitHub App Manifest. These settings will be used by default when
# initially configuring your GitHub App.
#
# NOTE: changing this file will not update your GitHub App settings.
# You must visit github.com/settings/apps/your-app-name to edit them.
#
# Read more about configuring your GitHub App:
# https://probot.github.io/docs/development/#configuring-a-github-app
#
# Read more about GitHub App Manifests:
# https://developer.github.com/apps/building-github-apps/creating-github-apps-from-a-manifest/

# The list of events the GitHub App subscribes to.
# Uncomment the event names below to enable them.
default_events:
# - check_run
# - check_suite
# - commit_comment
# - create
# - delete
# - deployment
# - deployment_status
# - fork
# - gollum
# - issue_comment
- issues
# - label
# - milestone
# - member
# - membership
# - org_block
# - organization
# - page_build
# - project
# - project_card
# - project_column
# - public
- pull_request
# - pull_request_review
# - pull_request_review_comment
# - push
# - release
# - repository
# - repository_import
# - status
# - team
# - team_add
# - watch

# The set of permissions needed by the GitHub App. The format of the object uses
# the permission name for the key (for example, issues) and the access type for
# the value (for example, write).
# Valid values are `read`, `write`, and `none`
default_permissions:
# Repository creation, deletion, settings, teams, and collaborators.
# https://developer.github.com/v3/apps/permissions/#permission-on-administration
# administration: read

# Checks on code.
# https://developer.github.com/v3/apps/permissions/#permission-on-checks
# checks: read

# Repository contents, commits, branches, downloads, releases, and merges.
# https://developer.github.com/v3/apps/permissions/#permission-on-contents
# contents: read

# Deployments and deployment statuses.
# https://developer.github.com/v3/apps/permissions/#permission-on-deployments
# deployments: read

# Issues and related comments, assignees, labels, and milestones.
# https://developer.github.com/v3/apps/permissions/#permission-on-issues
issues: write

# Search repositories, list collaborators, and access repository metadata.
# https://developer.github.com/v3/apps/permissions/#metadata-permissions
metadata: read

# Retrieve Pages statuses, configuration, and builds, as well as create new builds.
# https://developer.github.com/v3/apps/permissions/#permission-on-pages
# pages: read

# Pull requests and related comments, assignees, labels, milestones, and merges.
# https://developer.github.com/v3/apps/permissions/#permission-on-pull-requests
pull_requests: write

# Manage the post-receive hooks for a repository.
# https://developer.github.com/v3/apps/permissions/#permission-on-repository-hooks
# repository_hooks: read

# Manage repository projects, columns, and cards.
# https://developer.github.com/v3/apps/permissions/#permission-on-repository-projects
# repository_projects: read

# Retrieve security vulnerability alerts.
# https://developer.github.com/v4/object/repositoryvulnerabilityalert/
# vulnerability_alerts: read

# Commit statuses.
# https://developer.github.com/v3/apps/permissions/#permission-on-statuses
# statuses: read

# Organization members and teams.
# https://developer.github.com/v3/apps/permissions/#permission-on-members
# members: read

# View and manage users blocked by the organization.
# https://developer.github.com/v3/apps/permissions/#permission-on-organization-user-blocking
# organization_user_blocking: read

# Manage organization projects, columns, and cards.
# https://developer.github.com/v3/apps/permissions/#permission-on-organization-projects
# organization_projects: read

# Manage team discussions and related comments.
# https://developer.github.com/v3/apps/permissions/#permission-on-team-discussions
# team_discussions: read

# Manage the post-receive hooks for an organization.
# https://developer.github.com/v3/apps/permissions/#permission-on-organization-hooks
# organization_hooks: read

# Get notified of, and update, content references.
# https://developer.github.com/v3/apps/permissions/
# organization_administration: read


# The name of the GitHub App. Defaults to the name specified in package.json
# name: My Probot App

# The homepage of your GitHub App.
# url: https://example.com/

# A description of the GitHub App.
# description: A description of my awesome app

# Set to true when your GitHub App is available to the public or false when it is only accessible to the owner of the app.
# Default: true
# public: false
86 changes: 86 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// let addChangesetUrl = `${
// github.context.payload.pull_request!.head.repo.html_url
// }/new/${
// github.context.payload.pull_request!.head.ref
// }?filename=.changeset/${humanId({
// separator: "-",
// capitalize: false
// })}.md`;

const getAbsentMessage = commitSha => `### 💥 No Changeset
Latest commit: ${commitSha}
Merging this PR will not cause any packages to be released. If these changes should not cause updates to packages in this repo, this is fine 🙂
**If these changes should be published to npm, you need to add a changeset.**
[Click here to learn what changesets are, and how to add one](https://github.com/Noviny/changesets/blob/master/docs/adding-a-changeset.md).
`;

const getApproveMessage = commitSha => `### 🦋 Changeset is good to go
Latest commit: ${commitSha}
**We got this.**
Not sure what this means? [Click here to learn what changesets are](https://github.com/Noviny/changesets/blob/master/docs/adding-a-changeset.md).`;

const getCommentId = (context, params) =>
context.github.issues.listComments(params).then(comments => {
const changesetBotComment = comments.data.find(
comment => comment.user.login === "changeset-bot[bot]"
);
return changesetBotComment ? changesetBotComment.id : null;
});

const getChangesetId = (context, params) =>
context.github.pullRequests.listFiles(params).then(files => {
const changesetFiles = files.data.filter(
file => file.filename.startsWith(".changeset") && file.status === "added"
);
return changesetFiles.length > 0;
});

const getLatestCommit = (context, params) =>
context.github.pullRequests.listCommits(params).then(commits => {
return commits.data.pop();
});

module.exports = app => {
app.log("Yay, the app was loaded!");

// Get an express router to expose new HTTP endpoints
// Healthcheck
const router = app.route("/");
router.get("/healthcheck", (req, res) => {
res.send("OK");
});

app.on(["pull_request.opened", "pull_request.synchronize"], async context => {
const params = context.issue();

const commentId = await getCommentId(context, params);
const hasChangeset = await getChangesetId(context, params);
const latestCommit = await getLatestCommit(context, params);

let prComment;
if (!hasChangeset) {
prComment = context.issue({
comment_id: commentId,
body: getAbsentMessage(latestCommit.sha)
});
} else {
prComment = context.issue({
comment_id: commentId,
body: getApproveMessage(latestCommit.sha)
});
}

if (commentId) {
return context.github.issues.updateComment(prComment);
}
return context.github.issues.createComment(prComment);
});
};
Loading

1 comment on commit c9af076

@vercel
Copy link

@vercel vercel bot commented on c9af076 Oct 4, 2019

Choose a reason for hiding this comment

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

Now could not deploy this pull request since it contains the following references to invalid secrets in the env sections of the now.json file:

  • app-id (in env: APP_ID)
  • webhook-secret (in env: WEBHOOK_SECRET)
  • private-key-base64-encoded (in env: PRIVATE_KEY)

Add those secrets or remove them from the env maps in the now.json file.

Please sign in to comment.