This repository has been archived by the owner on Mar 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from proshunsuke/v2
v2
- Loading branch information
Showing
31 changed files
with
5,003 additions
and
4,474 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
{"scriptId":"1nm2BIhYyOpqUmj-vKRr4p69bhMEGBf-Cq9opE4u3xvfyd67C38majtmI","rootDir":"./dist","projectId":"augc-260709"} | ||
{ | ||
"scriptId":"1rzoffgXqdRqq98pRPxJSCMJnLmJ3cUTyhpjZsfm54WbHByH7swQv7n8V", | ||
"rootDir":"./dist" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module.exports = { | ||
root: true, | ||
env: { | ||
es6: true, | ||
node: true, | ||
}, | ||
parser: '@typescript-eslint/parser', | ||
parserOptions: { | ||
sourceType: 'module', | ||
ecmaVersion: 2018, | ||
project: ['./tsconfig.eslint.json'], | ||
}, | ||
plugins: ['@typescript-eslint', 'jest'], | ||
extends: [ | ||
'airbnb-typescript/base', | ||
'plugin:@typescript-eslint/recommended', | ||
'plugin:@typescript-eslint/recommended-requiring-type-checking', | ||
'prettier', | ||
], | ||
rules: { | ||
quotes: ['error', 'single', { 'avoidEscape': true, 'allowTemplateLiterals': false }], | ||
semi: ['error', 'always'], | ||
'import/no-extraneous-dependencies': 'off', | ||
'no-void': ['error', { allowAsStatement: true }], | ||
'no-console': ['error', { allow: ['info', 'error'] }], | ||
'@typescript-eslint/unbound-method': 'off' | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
node_modules | ||
package.json | ||
yarn.lock | ||
tsconfig.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"singleQuote": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,52 @@ | ||
NODE_MODULUES_BIN_DIR := ./node_modules/.bin | ||
|
||
setup: | ||
$(MAKE) yarn/install | ||
|
||
yarn/install: | ||
install: | ||
yarn install | ||
|
||
webpack/build: | ||
$(NODE_MODULUES_BIN_DIR)/webpack | ||
build: install | ||
ENV=production yarn webpack | ||
|
||
watch: | ||
ENV=local yarn webpack watch | ||
|
||
server: | ||
yarn run functions-framework --target=getKeyakiSchedule --source=./gcpFunctions/getKeyakiSchedule | ||
|
||
run/setSchedule: | ||
node -e 'require("./dist/index.js");global.setSchedule();' | ||
|
||
clasp/login: | ||
$(NODE_MODULUES_BIN_DIR)/clasp login | ||
login: | ||
yarn clasp login | ||
|
||
clasp/push: yarn/install webpack/build | ||
$(NODE_MODULUES_BIN_DIR)/clasp push -f | ||
push: build | ||
yarn clasp push -f | ||
|
||
clasp/run: | ||
$(NODE_MODULUES_BIN_DIR)/clasp run execute | ||
run: | ||
yarn clasp run execute | ||
|
||
clasp/open: | ||
$(NODE_MODULUES_BIN_DIR)/clasp open | ||
open: | ||
yarn clasp open | ||
|
||
clasp/logs: | ||
$(NODE_MODULUES_BIN_DIR)/clasp logs | ||
logs: | ||
yarn clasp logs | ||
|
||
test: | ||
$(NODE_MODULUES_BIN_DIR)/jest | ||
ENV=production yarn jest | ||
|
||
test/ci: | ||
$(MAKE) webpack/build | ||
$(NODE_MODULUES_BIN_DIR)/jest --coverage | ||
$(MAKE) build | ||
ENV=production yarn jest --coverage | ||
|
||
lint: | ||
yarn eslint "src/**/*.ts" "tests/**/*.ts" | ||
|
||
fix: | ||
$(MAKE) fix/prettier | ||
$(MAKE) fix/eslint | ||
|
||
fix/eslint: | ||
yarn eslint "src/**/*.ts" "tests/**/*.ts" --fix | ||
|
||
fix/prettier: | ||
yarn prettier --check --write "src/**/*.ts" "tests/**/*.ts" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,7 +70,7 @@ make test | |
### リリース | ||
|
||
```shell script | ||
make clasp/push | ||
make push | ||
``` | ||
|
||
## 連絡先 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require('jest-fetch-mock').enableMocks() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,55 @@ | ||
import { ScheduleObj, KeyakiCalendarObj, keyakiCalendarIds} from "./keyakizaka/keyakiObjects" | ||
import Retry from "./lib/retry"; | ||
import { | ||
ScheduleObj, | ||
KeyakiCalendarObj, | ||
keyakiCalendarIds, | ||
} from './keyakizaka/keyakiObjects'; | ||
import Retry from './lib/retry'; | ||
|
||
export default class Calendar { | ||
/** | ||
* | ||
* @param {GoogleAppsScript.Calendar.CalendarEvent} event | ||
*/ | ||
deleteEvent(event: GoogleAppsScript.Calendar.CalendarEvent): void { | ||
Retry.retryable(3, () => { | ||
event.deleteEvent(); | ||
}); | ||
Utilities.sleep(500); // API制限に引っかかってそうなのでsleepする | ||
/** | ||
* | ||
* @param {GoogleAppsScript.Calendar.CalendarEvent} event | ||
*/ | ||
static deleteEvent(event: GoogleAppsScript.Calendar.CalendarEvent): void { | ||
Retry.retryable(3, () => { | ||
event.deleteEvent(); | ||
}); | ||
if (process.env.ENV === 'production') { | ||
Utilities.sleep(500); // API制限に引っかかってそうなのでsleepする | ||
} | ||
} | ||
|
||
/** | ||
* | ||
* @param {ScheduleObj} schedule | ||
*/ | ||
createEvent(schedule: ScheduleObj): void { | ||
const keyakiCalendarId: KeyakiCalendarObj | undefined = keyakiCalendarIds.find((keyakiCalendarId: KeyakiCalendarObj) => { | ||
return (keyakiCalendarId.kind === schedule.className); | ||
}); | ||
if (typeof keyakiCalendarId === 'undefined') { | ||
console.info("スケジュールの内容: "); | ||
console.info(schedule); | ||
throw new Error("存在しない種類のスケジュールです。className: " + schedule.className); | ||
} | ||
const calendarId: string = keyakiCalendarId.calendarId; | ||
Retry.retryable(3, () => { | ||
CalendarApp.getCalendarById(calendarId).createAllDayEvent(schedule.title, new Date(schedule.start)); | ||
}); | ||
console.info("予定を作成しました。日付: " + schedule.start + ", タイトル: " + schedule.title); | ||
Utilities.sleep(500); // API制限に引っかかってそうなのでsleepする | ||
}; | ||
/** | ||
* | ||
* @param {ScheduleObj} schedule | ||
*/ | ||
static createEvent(schedule: ScheduleObj): void { | ||
const keyakiCalendarId: | ||
| KeyakiCalendarObj | ||
| undefined = keyakiCalendarIds.find( | ||
(id) => id.kind === schedule.className | ||
); | ||
if (typeof keyakiCalendarId === 'undefined') { | ||
console.info('スケジュールの内容: '); | ||
console.info(schedule); | ||
throw new Error( | ||
`存在しない種類のスケジュールです。className: ${schedule.className}` | ||
); | ||
} | ||
const { calendarId } = keyakiCalendarId; | ||
Retry.retryable(3, () => { | ||
if (process.env.ENV === 'production') { | ||
CalendarApp.getCalendarById(calendarId).createAllDayEvent( | ||
schedule.title, | ||
new Date(schedule.start) | ||
); | ||
} | ||
}); | ||
console.info( | ||
`予定を作成しました。日付: ${schedule.start}, タイトル: ${schedule.title}` | ||
); | ||
if (process.env.ENV === 'production') { | ||
Utilities.sleep(500); // API制限に引っかかってそうなのでsleepする | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,23 @@ | ||
import Schedule from "./schedule"; | ||
import Trigger from "./lib/trigger"; | ||
import dayjs from "dayjs"; | ||
import dayjs from 'dayjs'; | ||
import Schedule from './schedule'; | ||
import Trigger from './lib/trigger'; | ||
import 'regenerator-runtime'; | ||
|
||
// @ts-ignore | ||
declare const global: { | ||
[x: string]: any; | ||
[x: string]: () => void | Promise<void>; | ||
}; | ||
|
||
/** | ||
* | ||
* @param e | ||
*/ | ||
global.createSetScheduleTrigger = function (e: any) { | ||
console.info("スケジュール更新のトリガーを作成します"); | ||
Trigger.setTrigger(dayjs()); | ||
console.info("スケジュール更新のトリガーを作成しました"); | ||
global.createSetScheduleTrigger = (): void => { | ||
console.info('スケジュール更新のトリガーを作成します'); | ||
Trigger.setTrigger(dayjs()); | ||
console.info('スケジュール更新のトリガーを作成しました'); | ||
}; | ||
|
||
/** | ||
* | ||
* @param e | ||
*/ | ||
global.setSchedule = function (e: any) { | ||
const schedule = new Schedule(); | ||
console.info("スケジュール更新を開始します"); | ||
schedule.setSchedule(); | ||
console.info("スケジュール更新が完了しました"); | ||
global.setSchedule = async (): Promise<void> => { | ||
console.info('スケジュール更新を開始します'); | ||
await Schedule.setSchedule(); | ||
console.info('スケジュール更新が完了しました'); | ||
}; | ||
|
||
export const createSetScheduleTrigger = global.createSetScheduleTrigger; | ||
export const setSchedule = global.setSchedule; | ||
export const { createSetScheduleTrigger } = global; | ||
export const { setSchedule } = global; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import fetch from 'node-fetch'; | ||
|
||
// eslint-disable-next-line import/prefer-default-export | ||
export async function fetchUrl(customUrl: string): Promise<string> { | ||
const response = await fetch(customUrl); | ||
return response.text(); | ||
} |
Oops, something went wrong.