Skip to content

Commit e3acaf7

Browse files
Resolve some linting
Signed-off-by: Peter Zhu <zhujiaxi@amazon.com>
1 parent 9b4854b commit e3acaf7

12 files changed

+26
-53
lines changed

.eslintrc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ module.exports = {
2727
'max-classes-per-file': 'off',
2828
'no-new': 'off',
2929
"no-console": "off",
30-
'max-len': ['error', { code: 120, ignoreComments: true }],
30+
'max-len': ['error', { code: 160, ignoreComments: true }],
3131
},
3232
};

.prettierrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"printWidth": 100,
2+
"printWidth": 160,
33
"tabWidth": 2,
44
"useTabs": false,
55
"semi": true,

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"start": "npm run clean && npm run build && probot run ./bin/app.js",
1919
"clean": "rm -rf ./bin/*",
2020
"format": "prettier --write \"src/**/*.{js,ts}\" \"test/**/*.ts\" \"configs/**/*.{yaml,yml}\"",
21-
"lint": "eslint --fix \"src/**/*.ts\" \"test/**/*.ts\" --ignore-pattern \"**/*.d.ts\"",
21+
"lint": "eslint --fix \"src/**/*.ts\" --ignore-pattern \"**/*.d.ts\"",
2222
"test": "jest"
2323
},
2424
"dependencies": {

src/app.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@ export default async (app: Probot) => {
66
app.log.info('OpenSearch Automation App is starting now......');
77

88
const srvObj = new Service('Hello World Service');
9-
await srvObj.initService(
10-
'configs/resources/peterzhu-organization.yml',
11-
'configs/operations/hello-world.yml',
12-
app,
13-
);
9+
await srvObj.initService('configs/resources/peterzhu-organization.yml', 'configs/operations/hello-world.yml', app);
1410
await srvObj.registerEvents();
1511

1612
app.log.info('All objects initialized, start listening events......');

src/call/create-issue-comment.ts

+2-10
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,12 @@ export interface CreateIssueCommentParams {
1212
tagUser?: string;
1313
}
1414

15-
export default async function createIssueComment(
16-
app: Probot,
17-
context: any,
18-
{ text }: CreateIssueCommentParams,
19-
): Promise<void> {
15+
export default async function createIssueComment(app: Probot, context: any, { text }: CreateIssueCommentParams): Promise<void> {
2016
const comment = context.issue({ body: dedent`${text}` });
2117
context.octokit.issues.createComment(comment);
2218
}
2319

24-
export async function createIssueCommentTagUser(
25-
app: Probot,
26-
context: any,
27-
{ text, tagUser }: CreateIssueCommentParams,
28-
): Promise<void> {
20+
export async function createIssueCommentTagUser(app: Probot, context: any, { text, tagUser }: CreateIssueCommentParams): Promise<void> {
2921
const comment = context.issue({ body: dedent`@${tagUser}: ${text}` });
3022
context.octokit.issues.createComment(comment);
3123
}

src/call/print-to-console.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ export interface PrintToConsoleParams {
99
text: string;
1010
}
1111

12-
export default async function printToConsole(
13-
app: Probot,
14-
context: any,
15-
{ text }: PrintToConsoleParams,
16-
): Promise<void> {
12+
export default async function printToConsole(app: Probot, context: any, { text }: PrintToConsoleParams): Promise<void> {
1713
app.log.info(text);
1814
}

src/config/resource-config.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,7 @@ export class ResourceConfig extends Config {
105105
private async __initOrganizations(): Promise<Map<string, Organization>> {
106106
const orgObjMap = new Map<string, Organization>();
107107
for (const orgData of (this.configData as ResourceData).organizations) {
108-
const orgObj = new Organization(
109-
orgData.name,
110-
await this.__initProjects(orgData),
111-
await this.__initRepositories(orgData),
112-
);
108+
const orgObj = new Organization(orgData.name, await this.__initProjects(orgData), await this.__initRepositories(orgData));
113109
await orgObj.setContext(this.octokit);
114110
orgObjMap.set(orgData.name, orgObj);
115111
}

src/service/operation/task.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ export class Task {
1515
this.callFunc = callArray[1];
1616
this.callArgs = callArgs;
1717
const randomString = require('randomstring');
18-
const namePostfix = randomString.generate({ length: 8, charset: 'alphanumeric' });
18+
const namePostfix = randomString.generate({
19+
length: 8,
20+
charset: 'alphanumeric',
21+
});
1922
this.name = name ? `${name}#${namePostfix}` : `${this.callName}#${namePostfix}`;
2023
}
2124

src/service/resource/issue.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ export class Issue extends Entity {
3030
repo: this.repositoryName,
3131
pull_number: this.issueNumber,
3232
});
33-
console.log(
34-
`Set issue context: ${this.orgName}/${this.repositoryName}#${this.issueNumber}`,
35-
);
33+
console.log(`Set issue context: ${this.orgName}/${this.repositoryName}#${this.issueNumber}`);
3634
}
3735
this.nodeId = this.context.data.node_id;
3836
} catch (e) {

src/service/resource/project-field.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,21 @@ export class ProjectField extends Entity {
5555
}
5656
`;
5757
const allFieldContextArray: any = await octokit.graphql(projFieldQuery);
58-
console.log(
59-
`Set projectfield context: ${this.orgName}/project/${this.projectNumber}/field/${this.fieldName}`,
60-
);
58+
console.log(`Set projectfield context: ${this.orgName}/project/${this.projectNumber}/field/${this.fieldName}`);
6159

6260
// There are total of 5 datatypes for GitHub Project Fields
6361
// The ProjectV2Field map to TEXT NUMBER DATE
6462
// While ProjectV2IterationField map to ITERATION, and ProjectV2SingleSelectField map to SINGLE_SELECT
65-
for (const fieldContext of allFieldContextArray.node.fields.nodes) {
66-
if (this.fieldName === fieldContext.name) {
67-
this.nodeId = fieldContext.id;
68-
this.fieldType = fieldContext.dataType;
69-
this.context = fieldContext;
70-
break;
71-
}
63+
64+
const fieldContext = allFieldContextArray.node.fields.nodes.find((field: Record<string, string>) => field.name === this.fieldName);
65+
66+
if (!fieldContext) {
67+
throw new Error(`${this.fieldName} not found! Please check organization ${this.orgName} project ${this.projectNumber} and verify that field exist.`);
7268
}
69+
70+
this.nodeId = fieldContext.id;
71+
this.fieldType = fieldContext.dataType;
72+
this.context = fieldContext;
7373
} catch (e) {
7474
console.error(`ERROR: ${e}`);
7575
}

src/service/service.ts

+2-8
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,7 @@ export class Service {
3232
return this.operation;
3333
}
3434

35-
public async initService(
36-
resourceConfigPath: string,
37-
operationConfigPath: string,
38-
app: Probot,
39-
): Promise<void> {
35+
public async initService(resourceConfigPath: string, operationConfigPath: string, app: Probot): Promise<void> {
4036
app.log.info(`Initializing Service: ${this.name} `);
4137
// Get octokit client so Resource object will get context
4238
const octokit = await octokitAuth(app, Number(process.env.INSTALLATION_ID));
@@ -81,9 +77,7 @@ export class Service {
8177
if (typeof callFuncCustom === 'function') {
8278
await callFuncCustom(this.app, context, { ...callArgs });
8379
} else {
84-
throw new Error(
85-
`${callFuncCustom} is not a function, please verify in ${callPath}`,
86-
);
80+
throw new Error(`${callFuncCustom} is not a function, please verify in ${callPath}`);
8781
}
8882
}
8983
}

test/index.test.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ const issueCreatedBody = { body: 'Thanks for opening this issue!' };
1818

1919
const privateKey = fs.readFileSync(path.join(__dirname, 'fixtures/mock-cert.pem'), 'utf-8');
2020

21-
const payload = JSON.parse(
22-
fs.readFileSync(path.join(__dirname, 'fixtures/issues.opened.json'), 'utf-8'),
23-
);
21+
const payload = JSON.parse(fs.readFileSync(path.join(__dirname, 'fixtures/issues.opened.json'), 'utf-8'));
2422

2523
describe('My Probot app', () => {
2624
let probot: any;

0 commit comments

Comments
 (0)