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

Run prettier as a pre-commit hook #75

Merged
merged 1 commit into from
Oct 9, 2024
Merged
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
1 change: 1 addition & 0 deletions .husky/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx lint-staged
2 changes: 1 addition & 1 deletion .prettierrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ module.exports = {
useTabs: false,
semi: true,
trailingComma: "es5",
bracketSpacing: true
bracketSpacing: true,
};
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ For testing, save your envvars to `.env`. `.env.default` has the required variab
### Deployment

Prerequisites:

- Make sure you have updated the version number in `package.json`.
- If updating Linear's app, you'll need to have access to Linear's Zapier account and generate a deploy key in `Settings > Deploy Keys`. You can then authenticate with the key using `zapier login --sso`.
- If updating Linear's app, you'll need to have access to Linear's Zapier account and generate a deploy key in `Settings > Deploy Keys`. You can then authenticate with the key using `zapier login --sso`.

You can deploy the app to Zapier with `yarn zapier-push`. This will also run `yarn zapier-validate` before deploying.

Expand Down
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
"zapier-dev": "tsc --watch",
"zapier-validate": "npm run zapier-build && zapier validate",
"zapier-push": "npm run zapier-validate && zapier push",
"prepare": "npm run zapier-build",
"prepare": "npm run zapier-build && husky install",
"pretest": "npm run zapier-build",
"test": "jest --passWithNoTests lib",
"prettier": "npx prettier --write **/*.{json,ts,js}"
"prettier": "npx prettier --write ."
},
"engines": {
"node": ">=18.0.0",
Expand All @@ -27,7 +27,13 @@
"devDependencies": {
"@types/jest": "^29.5.12",
"@types/node": "^18.11.9",
"husky": ">=6",
"jest": "^29.7.0",
"lint-staged": ">=10",
"prettier": "^3.3.3",
"typescript": "^5.3.3"
},
"lint-staged": {
"*.{js,ts,json}": "prettier --write"
}
}
57 changes: 25 additions & 32 deletions src/samples/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,33 @@
"createdAt": "2024-10-04T22:38:43.396Z",
"startDate": "2024-10-05T22:38:43.396Z",
"targetDate": null,
"status":
{
"id": "f5d6c8d3-fac2-482c-a1b0-565718d9b103",
"name": "Test status",
"type": "backlog"
"status": {
"id": "f5d6c8d3-fac2-482c-a1b0-565718d9b103",
"name": "Test status",
"type": "backlog"
},
"teams":
{
"nodes":
[
{
"id": "cd718ff4-d8e3-4569-aa41-082d512a1809",
"name": "US Team"
}
]
"teams": {
"nodes": [
{
"id": "cd718ff4-d8e3-4569-aa41-082d512a1809",
"name": "US Team"
}
]
},
"initiatives":
{
"nodes":
[
{
"id": "6d6cbf03-dd67-47c6-ae21-d1b2519454e3",
"name": "Product"
}
]
"initiatives": {
"nodes": [
{
"id": "6d6cbf03-dd67-47c6-ae21-d1b2519454e3",
"name": "Product"
}
]
},
"projectMilestones":
{
"nodes":
[
{
"id": "acd884e4-c056-43b5-9a07-f4adb213a8ca",
"name": "V1"
}
]
"projectMilestones": {
"nodes": [
{
"id": "acd884e4-c056-43b5-9a07-f4adb213a8ca",
"name": "V1"
}
]
}
}
128 changes: 74 additions & 54 deletions src/triggers/estimate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,85 +17,101 @@ enum EstimationType {
tShirt = "tShirt",
}

type TeamResponse ={
type TeamResponse = {
data: {
team: {
issueEstimationAllowZero: boolean;
issueEstimationExtended: boolean;
issueEstimationType: EstimationType;
};
};
}
};

const optionsForType = (type: EstimationType, allowZero: boolean, extended: boolean): {id: number, label: string}[] => {
const optionsForType = (
type: EstimationType,
allowZero: boolean,
extended: boolean
): { id: number; label: string }[] => {
const result = [];
if (allowZero) {
result.push(type === EstimationType.tShirt ? {id: 0, label: '-'} : {id: 0, label: '0 Points'})
result.push(type === EstimationType.tShirt ? { id: 0, label: "-" } : { id: 0, label: "0 Points" });
}

switch (type) {
case EstimationType.notUsed:
return [];
case EstimationType.exponential:
return result.concat(
[
{id: 1, label: '1 Point'},
{id: 2, label: '2 Points'},
{id: 4, label: '4 Points'},
{id: 8, label: '8 Points'},
{ id: 16, label: '16 Points'}
]).concat(
extended ? [
{ id: 32, label: '32 Points'},
{ id: 64, label: '64 Points'}
] : []
return result
.concat([
{ id: 1, label: "1 Point" },
{ id: 2, label: "2 Points" },
{ id: 4, label: "4 Points" },
{ id: 8, label: "8 Points" },
{ id: 16, label: "16 Points" },
])
.concat(
extended
? [
{ id: 32, label: "32 Points" },
{ id: 64, label: "64 Points" },
]
: []
);
case EstimationType.fibonacci:
return result.concat(
[
{id: 1, label: '1 Point'},
{id: 2, label: '2 Points'},
{id: 3, label: '3 Points'},
{id: 5, label: '5 Points'},
{id: 8, label: '8 Points'},
]).concat(
extended ? [
{ id: 13, label: '13 Points'},
{ id: 21, label: '21 Points'},
] : []
return result
.concat([
{ id: 1, label: "1 Point" },
{ id: 2, label: "2 Points" },
{ id: 3, label: "3 Points" },
{ id: 5, label: "5 Points" },
{ id: 8, label: "8 Points" },
])
.concat(
extended
? [
{ id: 13, label: "13 Points" },
{ id: 21, label: "21 Points" },
]
: []
);
case EstimationType.linear:
return result.concat(
[
{id: 1, label: '1 Point'},
{id: 2, label: '2 Points'},
{id: 3, label: '3 Points'},
{id: 4, label: '4 Points'},
{id: 5, label: '5 Points'},
]).concat(
extended ? [
{id: 6, label: '6 Points'},
{id: 7, label: '7 Points'},
] : []
return result
.concat([
{ id: 1, label: "1 Point" },
{ id: 2, label: "2 Points" },
{ id: 3, label: "3 Points" },
{ id: 4, label: "4 Points" },
{ id: 5, label: "5 Points" },
])
.concat(
extended
? [
{ id: 6, label: "6 Points" },
{ id: 7, label: "7 Points" },
]
: []
);
case EstimationType.tShirt:
return result.concat(
[
{id: 1, label: 'XS'},
{id: 2, label: 'S'},
{id: 3, label: 'M'},
{id: 5, label: 'L'},
{id: 8, label: 'XL'},
]).concat(
extended ? [
{ id: 13, label: 'XXL'},
{ id: 21, label: 'XXXL'},
] : []
return result
.concat([
{ id: 1, label: "XS" },
{ id: 2, label: "S" },
{ id: 3, label: "M" },
{ id: 5, label: "L" },
{ id: 8, label: "XL" },
])
.concat(
extended
? [
{ id: 13, label: "XXL" },
{ id: 21, label: "XXXL" },
]
: []
);
default:
return [];
}
}
};

const getEstimateOptions = async (z: ZObject, bundle: Bundle) => {
if (!bundle.inputData.team_id) {
Expand Down Expand Up @@ -125,7 +141,11 @@ const getEstimateOptions = async (z: ZObject, bundle: Bundle) => {
});

const data = (response.json as TeamResponse).data;
return optionsForType(data.team.issueEstimationType, data.team.issueEstimationAllowZero, data.team.issueEstimationExtended);
return optionsForType(
data.team.issueEstimationType,
data.team.issueEstimationAllowZero,
data.team.issueEstimationExtended
);
};

export const estimate = {
Expand Down
49 changes: 28 additions & 21 deletions src/triggers/issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ interface TeamIssuesResponse {
project?: {
id: string;
name: string;
}
};
projectMilestone?: {
id: string;
name: string;
}
};
creator: {
id: string;
name: string;
Expand All @@ -38,16 +38,16 @@ interface TeamIssuesResponse {
email: string;
};
status: {
id: string,
name: string,
type: string
},
id: string;
name: string;
type: string;
};
parent?: {
id: string;
identifier: string;
url: string;
title: string;
}
};
}[];
pageInfo: {
hasNextPage: boolean;
Expand All @@ -65,18 +65,21 @@ const buildIssueList = (orderBy: "createdAt" | "updatedAt") => async (z: ZObject

const cursor = bundle.meta.page ? await z.cursor.get() : undefined;

const variables = omitBy({
after: cursor,
teamId: bundle.inputData.team_id,
statusId: bundle.inputData.status_id,
creatorId: bundle.inputData.creator_id,
assigneeId: bundle.inputData.assignee_id,
priority: bundle.inputData.priority && Number(bundle.inputData.priority) || undefined,
labelId: bundle.inputData.label_id,
projectId: bundle.inputData.project_id,
projectMilestoneId: bundle.inputData.project_milestone_id,
orderBy,
}, v => v === undefined);
const variables = omitBy(
{
after: cursor,
teamId: bundle.inputData.team_id,
statusId: bundle.inputData.status_id,
creatorId: bundle.inputData.creator_id,
assigneeId: bundle.inputData.assignee_id,
priority: (bundle.inputData.priority && Number(bundle.inputData.priority)) || undefined,
labelId: bundle.inputData.label_id,
projectId: bundle.inputData.project_id,
projectMilestoneId: bundle.inputData.project_milestone_id,
orderBy,
},
(v) => v === undefined
);

const filters = [];
if ("priority" in variables) {
Expand Down Expand Up @@ -127,10 +130,14 @@ const buildIssueList = (orderBy: "createdAt" | "updatedAt") => async (z: ZObject
first: 10
after: $after
orderBy: $orderBy
${filters.length > 0 ?`
${
filters.length > 0
? `
filter: {
${filters.join("\n ")}
}` : ""}
}`
: ""
}
) {
nodes {
id
Expand Down
2 changes: 1 addition & 1 deletion src/triggers/team.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const getTeamList = async (z: ZObject, bundle: Bundle) => {
}
}`,
variables: {
after: cursor
after: cursor,
},
},
method: "POST",
Expand Down
4 changes: 2 additions & 2 deletions src/triggers/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const getUserList = async (z: ZObject, bundle: Bundle) => {
}
`,
variables: {
after: cursor
after: cursor,
},
},
method: "POST",
Expand All @@ -62,7 +62,7 @@ const getUserList = async (z: ZObject, bundle: Bundle) => {
await z.cursor.set(data.users.pageInfo.endCursor);
}

return users.map(user => ({
return users.map((user) => ({
name: `${user.name} (${user.displayName})`,
id: user.id,
}));
Expand Down
Loading
Loading