Skip to content

Commit

Permalink
Merge pull request #27 from k2tzumi/refacotr-settings
Browse files Browse the repository at this point in the history
Refactor settings
  • Loading branch information
k2tzumi authored Oct 30, 2023
2 parents 78def4b + db332a5 commit c454d02
Show file tree
Hide file tree
Showing 32 changed files with 6,807 additions and 8,223 deletions.
43 changes: 43 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"env": {
"es6": true,
"googleappsscript/googleappsscript": true
},
"extends": [
"plugin:@typescript-eslint/recommended",
"prettier"
],
"plugins": [
"@typescript-eslint",
"googleappsscript",
"prettier"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2019,
"sourceType": "module",
"project": "./tsconfig.json"
},
"rules": {
"prettier/prettier": "error",
"import/extensions": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/triple-slash-reference": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/naming-convention": [
"error",
{
"selector": "property",
"format": ["camelCase", "snake_case", "UPPER_CASE", "PascalCase"],
"leadingUnderscore": "allow"
}
],
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"error"
],
"no-useless-constructor": "off",
"@typescript-eslint/no-useless-constructor": "error",
"class-methods-use-this": "off"
}
}
36 changes: 23 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,54 +1,59 @@
.DEFAULT_GOAL := help

CLASP = npx @google/clasp

PROJECT_NAME := $(shell basename "$(CURDIR)")

.PHONY: help
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' Makefile | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

.clasp.json:
make login
clasp create --title hue-kintai-bot --type webapp --rootDir ./src
clasp setting fileExtension ts
# clasp setting filePushOrder
$(CLASP) create --title $(PROJECT_NAME) --type webapp --rootDir ./src
mv src/.clasp.json .
$(CLASP) setting fileExtension ts
# $(CLASP) setting filePushOrder
sed -i -e 's/}/,"filePushOrder":["src\/OAuth2Handler.ts","src\/SlackBaseHandler.ts","src\/BaseError.ts","src\/WorksClient.ts"]}/' .clasp.json
rm .clasp.json-e
rm -f .clasp.json-e

node_modules:
npm install
npm ci

.PHONY: login
login: ## Google login
login:
clasp login
$(CLASP) login

.PHONY: push
push: ## Push Google apps scripts
push: .clasp.json lint
clasp push -f
$(CLASP) push -f

.PHONY: deploy
deploy: ## Deploy Google apps scripts
deploy: .clasp.json
clasp deploy
$(CLASP) deploy -d "`npx -c 'echo \"$$npm_package_version\"'`"

.PHONY: redeploy
redeploy: ## Re-Deploy Google apps scripts
redeploy: .clasp.json
clasp deploy -i `clasp deployments | grep "web app meta-version" | cut -f2 -d" "` -d "web app meta-version"
$(CLASP) deploy --versionNumber `$(CLASP) versions | grep -o '^[0-9]*' | tail -n 1` -d "`npx -c 'echo \"$$npm_package_version\"'`"

.PHONY: open
open: ## Open Google apps scripts
open: .clasp.json
clasp open
$(CLASP) open

.PHONY: application
application: ## Open web application
application: .clasp.json
clasp open --webapp
$(CLASP) open --webapp

.PHONY: pull
pull: ## Pull Google apps scripts
pull: .clasp.json
clasp pull
$(CLASP) pull

.PHONY: lint
lint: ## Run tslint
Expand All @@ -63,4 +68,9 @@ test: node_modules
.PHONY: undeploy
undeploy: ## all undeploy Google apps scripts
undeploy:
clasp undeploy --all
$(CLASP) undeploy --all

.PHONY: npm-check-updates
npm-check-updates: ## npm check updates
npm-check-updates:
npx npm-check-updates -u
3 changes: 1 addition & 2 deletions __tests__/Code.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { Slack } from "../src/slack/types/index.d";
import * from "@types/google-apps-script";

type Commands = Slack.SlashCommand.Commands;

const properites = {
getProperty: jest.fn(function () {
return 'dummy';
return '{}';
}),
deleteAllProperties: jest.fn(),
deleteProperty: jest.fn(),
Expand Down
4 changes: 2 additions & 2 deletions __tests__/InteractivityHandler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('InteractivityHandler', () => {
it('success', () => {
const handler = new InteractivityHandler('token');

handler.addListener('type', (interaction: Interaction): { trigger_id: "trigger_id" } => { return {} });
handler.addListener('type', (interaction: Interaction): { trigger_id: "dummy" } => { return {} });
});
});
});
});
26 changes: 23 additions & 3 deletions __tests__/SlackApiClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,29 @@ describe('SlackApiClient', () => {
it('success', () => {
const client = new SlackApiClient('token');
response = { ok: true, scheduled_message_id: 1 };
const actual = client.chatScheduleMessage('channel', new Date("Mon, 06 Mar 2017 21:22:23 +0000"), 'text', [{}]);
const actual = client.chatScheduleMessage(
'channel',
new Date("Mon, 06 Mar 2017 21:22:23 +0000"),
null,
[
{
type: "header",
text: {
type: "plain_text",
text: "header"
}
},
{ type: "divider" },
{
type: "context",
elements: [
{ type: "plain_text", text: "context" }
]
}
]
);
expect(mockFetch.mock.calls[0][0]).toContain('chat.scheduleMessage');
expect(mockFetch.mock.calls[0][1]).toHaveProperty("payload", "{\"channel\":\"channel\",\"post_at\":1488835343,\"blocks\":[{}],\"text\":\"text\"}");
expect(mockFetch.mock.calls[0][1]).toHaveProperty("payload", "{\"channel\":\"channel\",\"post_at\":1488835343,\"blocks\":[{\"type\":\"header\",\"text\":{\"type\":\"plain_text\",\"text\":\"header\"}},{\"type\":\"divider\"},{\"type\":\"context\",\"elements\":[{\"type\":\"plain_text\",\"text\":\"context\"}]}],\"text\":\"header\\ncontext\"}");
expect(actual).toBe(1);
});
});
Expand All @@ -37,4 +57,4 @@ describe('SlackApiClient', () => {
expect(actual).toHaveProperty('test', true);
});
});
});
});
2 changes: 1 addition & 1 deletion __tests__/SlackHandler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ describe('SlackHandler', () => {
handler.addInteractivityListener('type', (blockActions: BlockActions): {} => { return {} });
});
});
});
});
2 changes: 1 addition & 1 deletion __tests__/SlackWebhooks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ describe('SlackWebhooks', () => {
expect(true).toStrictEqual(actual);
});
});
});
});
5 changes: 4 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ module.exports = {
testMatch: ["**/__tests__/**/*.[jt]s?(x)", "**/?(*.)+(spec|test).[jt]s?(x)"],
testEnvironment: 'node',
transform: {
'^.+\\.tsx?$': ['ts-jest', {diagnostics: false}],
'^.+\\.tsx?$': ['ts-jest', { tsconfig: "tsconfig.json", diagnostics: false }]
},
transformIgnorePatterns: [
"/node_modules/(?!apps-script-jobqueue)"
]
};
Loading

0 comments on commit c454d02

Please sign in to comment.