Skip to content
This repository has been archived by the owner on Mar 8, 2024. It is now read-only.
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: proshunsuke/augc
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v13
Choose a base ref
...
head repository: proshunsuke/augc
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 10 commits
  • 10 files changed
  • 1 contributor

Commits on Oct 17, 2021

  1. Copy the full SHA
    eac431a View commit details
  2. Copy the full SHA
    781d286 View commit details
  3. Copy the full SHA
    e873d27 View commit details
  4. Copy the full SHA
    96e143e View commit details
  5. Copy the full SHA
    fb22fac View commit details

Commits on Nov 27, 2021

  1. グッズ追加

    proshunsuke committed Nov 27, 2021
    Copy the full SHA
    f82f5cf View commit details
  2. Copy the full SHA
    d56097a View commit details
  3. Copy the full SHA
    686b231 View commit details
  4. Copy the full SHA
    2fcae6a View commit details
  5. Copy the full SHA
    5eda15e View commit details
Showing with 1,538 additions and 1,539 deletions.
  1. +3 −1 Makefile
  2. +1 −0 README.md
  3. +1 −0 src/lib/trigger.ts
  4. +7 −2 src/schedule.ts
  5. +4 −0 src/sites/sakurazaka/sakuraObjects.ts
  6. +34 −4 src/sites/siteSchedule.ts
  7. +2 −0 tests/calendar.test.ts
  8. +14 −9 tests/schedule.test.ts
  9. +2 −1 webpack.config.js
  10. +1,470 −1,522 yarn.lock
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
SITE_NAME=keyakizaka

setup:
$(MAKE) yarn/install

@@ -8,7 +10,7 @@ build: install
ENV=production yarn webpack

watch:
ENV=local yarn webpack watch
SITE_NAME=$(SITE_NAME) ENV=local yarn webpack watch

server/keyaki:
yarn run functions-framework --target=getKeyakiSchedule --source=./gcpFunctions/getKeyakiSchedule --port 8080
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -43,6 +43,7 @@ Auto Updating Google Calendar using google apps script
---|---
アルバム|https://calendar.google.com/calendar/ical/0ivcdulcqpm0majeaqo0f1bml8@group.calendar.google.com/public/basic.ics
イベント|https://calendar.google.com/calendar/ical/ulksj6q2hr6hvvre7jqk2rghe4@group.calendar.google.com/public/basic.ics
グッズ|https://calendar.google.com/calendar/ical/9p6fqjmf2s1k6ci1clmou1l7bg%40group.calendar.google.com/public/basic.ics
シングル|https://calendar.google.com/calendar/ical/rf2qon3acq2g8fj1iuvngmp7tg@group.calendar.google.com/public/basic.ics
その他|https://calendar.google.com/calendar/ical/06ol8jcjk0r5bviarevjicta70@group.calendar.google.com/public/basic.ics
テレビ|https://calendar.google.com/calendar/ical/14elrf80nstbrahsfe2iuem8fg@group.calendar.google.com/public/basic.ics
1 change: 1 addition & 0 deletions src/lib/trigger.ts
Original file line number Diff line number Diff line change
@@ -53,6 +53,7 @@ export default class Trigger {
* @returns {string | null}
*/
static getTargetSiteNameProperty(): string | null {
if (process.env.SITE_NAME) return process.env.SITE_NAME;
if (process.env.ENV !== 'production') return null;
const properties = PropertiesService.getScriptProperties();
return properties.getProperty(TARGET_SITE_NAME_KEY);
9 changes: 7 additions & 2 deletions src/schedule.ts
Original file line number Diff line number Diff line change
@@ -9,8 +9,13 @@ export default class Schedule {
new KeyakiSiteSchedule(),
new SakuraSiteSchedule(),
];
for await (const siteSchedule of siteScheduleList) {
await siteSchedule.setSiteSchedule(startDate);
for (let i = 0; i < siteScheduleList.length; i++) {
const executed = await siteScheduleList[i].setSiteSchedule(
startDate,
siteScheduleList[i + 1]
);
// スケジュール登録をした場合は即終了。しなかった場合は既に登録済みなので次のサイトのスケジュール登録に進む
if (executed) return;
}
}
}
4 changes: 4 additions & 0 deletions src/sites/sakurazaka/sakuraObjects.ts
Original file line number Diff line number Diff line change
@@ -14,6 +14,10 @@ export const sakuraCalendarIds: SiteCalendarInterface[] = [
type: 'イベント',
calendarId: 'ulksj6q2hr6hvvre7jqk2rghe4@group.calendar.google.com',
},
{
type: 'グッズ',
calendarId: '9p6fqjmf2s1k6ci1clmou1l7bg@group.calendar.google.com',
},
{
type: 'シングル',
calendarId: 'rf2qon3acq2g8fj1iuvngmp7tg@group.calendar.google.com',
38 changes: 34 additions & 4 deletions src/sites/siteSchedule.ts
Original file line number Diff line number Diff line change
@@ -4,15 +4,31 @@ import Trigger, { TERMINATION_MINUTES } from '../lib/trigger';
import { SiteCalendarInterface } from '../calendarInterface';

export interface SiteScheduleInterface {
setSiteSchedule(startDate: dayjs.Dayjs): Promise<void>;
setSiteSchedule(
startDate: dayjs.Dayjs,
nextSiteSchedule?: SiteScheduleInterface
): Promise<boolean>;

siteCalendarUrl(): string;

siteCalendarIds(): SiteCalendarInterface[];

siteName(): string;
}

export default abstract class SiteSchedule implements SiteScheduleInterface {
async setSiteSchedule(startDate: dayjs.Dayjs): Promise<void> {
if (!this.doesExecute()) return;
/**
* スケジュール登録をした場合はtrue, しなかった場合はfalseを返す
*
* @param {dayjs.Dayjs} startDate
* @param nextSiteSchedule
* @returns {Promise<boolean>}
*/
async setSiteSchedule(
startDate: dayjs.Dayjs,
nextSiteSchedule?: SiteScheduleInterface
): Promise<boolean> {
if (!this.doesExecute()) return false;
console.info(`${this.siteName()}の予定を更新します`);
const beginningOfNexYearMonth = dayjs().startOf('month').add(1, 'year');
let targetBeginningOfMonth = SiteSchedule.getTargetBeginningOfMonth();
@@ -32,12 +48,26 @@ export default abstract class SiteSchedule implements SiteScheduleInterface {
'YYYY-MM-DD'
)}, 次実行するサイト: ${this.siteName()}`
);
return;
return true;
}
}

if (nextSiteSchedule) {
const thisMonth = dayjs().startOf('month');
Trigger.setTrigger(thisMonth, nextSiteSchedule.siteName());
console.info(
`${this.siteName()}の全てのスケジュール作成が完了したので次のトリガーをセットして終了します。次実行開始する月: ${thisMonth.format(
'YYYY-MM-DD'
)}, 次実行するサイト: ${nextSiteSchedule.siteName()}`
);
return true;
}

Trigger.deleteTargetDateProperty();
Trigger.deleteTargetSiteNameProperty();
Trigger.deleteTriggers();

return true;
}

/**
2 changes: 2 additions & 0 deletions tests/calendar.test.ts
Original file line number Diff line number Diff line change
@@ -56,6 +56,7 @@ describe('deleteEvent', (): void => {
const calendarEventMock: jest.Mock = jest.fn(() => ({
deleteEvent: deleteEventMock,
}));
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
Calendar.deleteEvent(calendarEventMock());
expect(deleteEventMock).toBeCalledTimes(1);
});
@@ -67,6 +68,7 @@ describe('deleteEvent', (): void => {
const calendarEventMock: jest.Mock = jest.fn(() => ({
deleteEvent: deleteEventMock,
}));
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
Calendar.deleteEvent(calendarEventMock());
expect(Utilities.sleep).not.toBeCalled();
});
23 changes: 14 additions & 9 deletions tests/schedule.test.ts
Original file line number Diff line number Diff line change
@@ -12,14 +12,14 @@ describe('setSchedule', (): void => {
jest.spyOn(console, 'info').mockImplementation();
jest.resetAllMocks();
});
it('setScheduleが24回呼ばれ各サイト1年分の予定が作成されること', async () => {
it('サイトの1年分のスケジュールが登録された場合は次のスケジュール登録は実行されずsetScheduleは12回実行されること', async () => {
await Schedule.setSchedule(dayjs());
expect(OneMonthSchedule.setSchedule).toBeCalledTimes(24);
expect(OneMonthSchedule.setSchedule).toBeCalledTimes(12);
});
it('propertiesに日付がセットされていた場合にその日付からスケジュール登録が始まること', async () => {
Trigger.getTargetDateProperty = jest.fn().mockReturnValueOnce('2020-01-01');
await Schedule.setSchedule(dayjs());
expect(OneMonthSchedule.setSchedule).toBeCalledTimes(23);
expect(OneMonthSchedule.setSchedule).toBeCalledTimes(11);
});
it('propertiesにサイト名がセットされていた場合にそのサイトからスケジュール登録が始まること', async () => {
Trigger.getTargetSiteNameProperty = jest
@@ -35,18 +35,23 @@ describe('setSchedule', (): void => {
.mockReturnValue(true);
Trigger.setTrigger = jest.fn().mockReturnThis();
await Schedule.setSchedule(dayjs());
expect(OneMonthSchedule.setSchedule).toBeCalledTimes(3);
expect(Trigger.setTrigger).toBeCalledTimes(2);
expect(OneMonthSchedule.setSchedule).toBeCalledTimes(2);
expect(Trigger.setTrigger).toBeCalledTimes(1);
});
it('指定時間内に全て実行出来たらdeleteTargetDatePropertyとdeleteTriggersが呼ばれること', async () => {
it('次にスケジュール登録するサイトが存在しない場合にdeleteTargetDatePropertyとdeleteTriggersが呼ばれること', async () => {
Trigger.hasExceededTerminationMinutes = jest.fn().mockReturnValue(false);
Trigger.setTrigger = jest.fn().mockReturnThis();
Trigger.deleteTargetDateProperty = jest.fn().mockReturnThis();
Trigger.deleteTargetSiteNameProperty = jest.fn().mockReturnThis();
Trigger.deleteTriggers = jest.fn().mockReturnThis();
Trigger.getTargetSiteNameProperty = jest
.fn()
.mockReturnValueOnce('sakurazaka');
await Schedule.setSchedule(dayjs());
expect(OneMonthSchedule.setSchedule).toBeCalledTimes(24);
expect(OneMonthSchedule.setSchedule).toBeCalledTimes(12);
expect(Trigger.setTrigger).not.toBeCalled();
expect(Trigger.deleteTargetDateProperty).toBeCalledTimes(2);
expect(Trigger.deleteTriggers).toBeCalledTimes(2);
expect(Trigger.deleteTargetDateProperty).toBeCalledTimes(1);
expect(Trigger.deleteTargetSiteNameProperty).toBeCalledTimes(1);
expect(Trigger.deleteTriggers).toBeCalledTimes(1);
});
});
3 changes: 2 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
@@ -12,7 +12,8 @@ const babelLoader = {
const plugins = [
new GasPlugin(),
new webpack.EnvironmentPlugin({
ENV: process.env.ENV || 'production'
ENV: process.env.ENV || 'production',
SITE_NAME: process.env.SITE_NAME || '',
})
];

2,992 changes: 1,470 additions & 1,522 deletions yarn.lock

Large diffs are not rendered by default.