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

feat: introduce todo-bot #4443

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/todo-bot/.c8rc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"exclude": [".mocharc.js", "build/test"]
}
7 changes: 7 additions & 0 deletions packages/todo-bot/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
build/
coverage/
node_modules/
.env
*.pem
Dockerfile
.dockerignore
4 changes: 4 additions & 0 deletions packages/todo-bot/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
**/node_modules
**/coverage
test/fixtures
build/
3 changes: 3 additions & 0 deletions packages/todo-bot/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "./node_modules/gts"
}
3 changes: 3 additions & 0 deletions packages/todo-bot/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
build
coverage
28 changes: 28 additions & 0 deletions packages/todo-bot/.mocharc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2022 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
const config = {
"enable-source-maps": true,
"throw-deprecation": true,
"timeout": 10000
}
if (process.env.MOCHA_THROW_DEPRECATION === 'false') {
delete config['throw-deprecation'];
}
if (process.env.MOCHA_REPORTER) {
config.reporter = process.env.MOCHA_REPORTER;
}
if (process.env.MOCHA_REPORTER_OUTPUT) {
config['reporter-option'] = `output=${process.env.MOCHA_REPORTER_OUTPUT}`;
}
module.exports = config
6 changes: 6 additions & 0 deletions packages/todo-bot/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
**/node_modules
**/coverage
test/fixtures
build/
docs/
protos/
17 changes: 17 additions & 0 deletions packages/todo-bot/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2022 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

module.exports = {
...require('gts/.prettierrc.json')
}
49 changes: 49 additions & 0 deletions packages/todo-bot/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Use a multi-stage docker build to limit production dependencies.

# Use the official lightweight Node.js 14 image.
# https://hub.docker.com/_/node
FROM node:14-slim AS BUILD

# Create and change to the app directory.
WORKDIR /usr/src/app

# Copy application dependency manifests to the container image.
# A wildcard is used to ensure copying both package.json AND package-lock.json (when available).
# Copying this first prevents re-running npm install on every code change.
COPY package*.json ./

# Install build dependencies.
RUN npm ci

# Now copy all the code so we can compile
COPY . ./

RUN npm run compile

FROM node:14-slim

# Create and change to the app directory.
WORKDIR /usr/src/app

COPY package*.json ./
COPY --from=BUILD /usr/src/app/build build
RUN npm ci --only=production

ENV NODE_ENV "production"

# Run the web service on container startup.
CMD [ "npm", "--no-update-notifier", "run", "start" ]
18 changes: 18 additions & 0 deletions packages/todo-bot/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# todo-bot

Instructions are provided in [googleapis/repo-automation-bots](https://github.com/googleapis/repo-automation-bots/blob/main/README.md) for deploying and testing your bots.

This bot uses nock for mocking requests to GitHub, and snap-shot-it for capturing responses; This allows updates to the API surface to be treated as a visual diff, rather than tediously asserting against each field.

## Running tests:

`npm test`

## Contributing

If you have suggestions for how todo-bot could be improved, or want to report a bug, open an issue! We'd love all and any contributions.

For more, check out the Contributing Guide.

License
Apache 2.0 © 2021 Google LLC.
33 changes: 33 additions & 0 deletions packages/todo-bot/cloudbuild-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

steps:
- name: gcr.io/cloud-builders/docker
id: 'build-docker'
waitFor: ['-']
dir: 'packages/todo-bot'
args:
- 'build'
- '-t'
- 'gcr.io/$PROJECT_ID/todo-bot'
- '.'

- name: gcr.io/gcp-runtimes/structure_test
args:
- '-i'
- 'gcr.io/$PROJECT_ID/todo-bot'
- '--config'
- 'todo-bot/container-test.yaml'
- '-v'
waitFor: ["build-docker"]
55 changes: 55 additions & 0 deletions packages/todo-bot/cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

steps:
- name: gcr.io/cloud-builders/docker
id: 'build-docker'
waitFor: ['-']
dir: packages/todo-bot
args:
- 'build'
- '-t'
- 'gcr.io/$PROJECT_ID/todo-bot'
- '.'

- name: gcr.io/cloud-builders/docker
id: 'push-docker'
waitFor: ['build-docker']
args: ['push', 'gcr.io/$PROJECT_ID/todo-bot']

- name: gcr.io/cloud-builders/gcloud
id: 'deploy-cloud-run'
waitFor: ['push-docker']
entrypoint: bash
args:
- '-e'
- './scripts/publish-cloud-run.sh'
- '$_DIRECTORY'
- '$PROJECT_ID'
- '$_BUCKET'
- '$_KEY_LOCATION'
- '$_KEY_RING'
- '$_FUNCTION_REGION'

- name: gcr.io/cloud-builders/npm
id: "cron-deploy"
waitFor: ["-"]
entrypoint: bash
args:
- "-e"
- "./scripts/cron-deploy.sh"
- "$_SCHEDULER_SERVICE_ACCOUNT_EMAIL"
- "$_FUNCTION_REGION"
- "$_REGION"
- "$_DIRECTORY"
22 changes: 22 additions & 0 deletions packages/todo-bot/container-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

schemaVersion: 1.0.0
commandTests:
- name: "git"
command: ["git", "--version"]
expectedOutput: ["git version 2.37.*"]
- name: "grep"
command: ["grep", "--version"]
expectedOutput: ["grep * 3.7"]
5 changes: 5 additions & 0 deletions packages/todo-bot/cron.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
cron:
- name: todo nightly scan
# crontab formatted schedule
schedule: 0 1 * * *
description: scan repositories nightly
Loading