Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 54a8873

Browse files
committed
Added error message if step fails
1 parent 1162b23 commit 54a8873

File tree

2 files changed

+163
-151
lines changed

2 files changed

+163
-151
lines changed

‎dist/index.js‎

Lines changed: 61 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,59 +1668,67 @@ var action_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _a
16681668

16691669
function action() {
16701670
return action_awaiter(this, void 0, void 0, function* () {
1671-
const NOTION_TOKEN_V2 = core.getInput('token_v2');
1672-
let id = core.getInput('database_id').replace(/-/g, '');
1673-
const databaseId = `${id.substr(0, 8)}-${id.substr(8, 4)}-${id.substr(12, 4)}-${id.substr(16, 4)}-${id.substr(20)}`;
1674-
const headers = {
1675-
Accept: 'application/json',
1676-
'Content-Type': 'application/json',
1677-
cookie: `token_v2=${NOTION_TOKEN_V2}`
1678-
};
1679-
const http = new http_client/* HttpClient */.eN(undefined, undefined, {
1680-
headers
1681-
});
1682-
const collectionView = yield ActionUtils.fetchData(databaseId, 'block', http);
1683-
core.info('Fetched database');
1684-
const collection_id = collectionView.collection_id;
1685-
const collection = yield ActionUtils.fetchData(collection_id, 'collection', http);
1686-
core.info('Fetched collection');
1687-
const response = yield http.post(`https://www.notion.so/api/v3/queryCollection`, JSON.stringify({
1688-
collection: {
1689-
id: collection_id,
1690-
spaceId: collectionView.space_id
1691-
},
1692-
collectionView: {
1693-
id: collectionView.view_ids[0],
1694-
spaceId: collectionView.space_id
1695-
},
1696-
query: {},
1697-
loader: {
1698-
type: 'table',
1699-
loadContentCover: false,
1700-
limit: 10000,
1701-
userTimeZone: ''
1702-
}
1703-
}));
1704-
const { recordMap } = JSON.parse(yield response.readBody());
1705-
core.info('Fetched rows');
1706-
const { schema } = collection;
1707-
const [category_schema_entry, color_schema_entry] = ActionUtils.getSchemaEntries(schema);
1708-
const rows = ActionUtils.modifyRows(recordMap, databaseId);
1709-
const categories_map = ActionUtils.constructCategoriesMap(category_schema_entry[1]);
1710-
ActionUtils.populateCategoriesMapItems(rows, category_schema_entry[0], categories_map);
1711-
const README_PATH = `${process.env.GITHUB_WORKSPACE}/README.md`;
1712-
core.info(`Reading from ${README_PATH}`);
1713-
const readmeLines = external_fs_default().readFileSync(README_PATH, 'utf-8').split('\n');
1714-
const [startIdx, endIdx] = ActionUtils.checkForSections(readmeLines);
1715-
const newLines = ActionUtils.constructNewContents(categories_map, color_schema_entry[0]);
1716-
const finalLines = [
1717-
...readmeLines.slice(0, startIdx + 1),
1718-
...newLines,
1719-
...readmeLines.slice(endIdx)
1720-
];
1721-
core.info(`Writing to ${README_PATH}`);
1722-
external_fs_default().writeFileSync(README_PATH, finalLines.join('\n'), 'utf-8');
1723-
yield ActionUtils.commitFile();
1671+
try {
1672+
const NOTION_TOKEN_V2 = core.getInput('token_v2');
1673+
let id = core.getInput('database_id').replace(/-/g, '');
1674+
const databaseId = `${id.substr(0, 8)}-${id.substr(8, 4)}-${id.substr(12, 4)}-${id.substr(16, 4)}-${id.substr(20)}`;
1675+
const headers = {
1676+
Accept: 'application/json',
1677+
'Content-Type': 'application/json',
1678+
cookie: `token_v2=${NOTION_TOKEN_V2}`
1679+
};
1680+
const http = new http_client/* HttpClient */.eN(undefined, undefined, {
1681+
headers
1682+
});
1683+
const collectionView = yield ActionUtils.fetchData(databaseId, 'block', http);
1684+
core.info('Fetched database');
1685+
const collection_id = collectionView.collection_id;
1686+
const collection = yield ActionUtils.fetchData(collection_id, 'collection', http);
1687+
core.info('Fetched collection');
1688+
const response = yield http.post(`https://www.notion.so/api/v3/queryCollection`, JSON.stringify({
1689+
collection: {
1690+
id: collection_id,
1691+
spaceId: collectionView.space_id
1692+
},
1693+
collectionView: {
1694+
id: collectionView.view_ids[0],
1695+
spaceId: collectionView.space_id
1696+
},
1697+
loader: {
1698+
type: 'reducer',
1699+
reducers: {
1700+
collection_group_results: {
1701+
type: 'results'
1702+
}
1703+
},
1704+
searchQuery: '',
1705+
userTimeZone: 'Asia/Dhaka'
1706+
}
1707+
}));
1708+
const { recordMap } = JSON.parse(yield response.readBody());
1709+
core.info('Fetched rows');
1710+
const { schema } = collection;
1711+
const [category_schema_entry, color_schema_entry] = ActionUtils.getSchemaEntries(schema);
1712+
const rows = ActionUtils.modifyRows(recordMap, databaseId);
1713+
const categories_map = ActionUtils.constructCategoriesMap(category_schema_entry[1]);
1714+
ActionUtils.populateCategoriesMapItems(rows, category_schema_entry[0], categories_map);
1715+
const README_PATH = `${process.env.GITHUB_WORKSPACE}/README.md`;
1716+
core.info(`Reading from ${README_PATH}`);
1717+
const readmeLines = external_fs_default().readFileSync(README_PATH, 'utf-8').split('\n');
1718+
const [startIdx, endIdx] = ActionUtils.checkForSections(readmeLines);
1719+
const newLines = ActionUtils.constructNewContents(categories_map, color_schema_entry[0]);
1720+
const finalLines = [
1721+
...readmeLines.slice(0, startIdx + 1),
1722+
...newLines,
1723+
...readmeLines.slice(endIdx)
1724+
];
1725+
core.info(`Writing to ${README_PATH}`);
1726+
external_fs_default().writeFileSync(README_PATH, finalLines.join('\n'), 'utf-8');
1727+
yield ActionUtils.commitFile();
1728+
}
1729+
catch (err) {
1730+
core.setFailed(err.message);
1731+
}
17241732
});
17251733
}
17261734

‎src/action.ts‎

Lines changed: 102 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -6,103 +6,107 @@ import fs from 'fs';
66
import { ActionUtils } from './utils';
77

88
export async function action() {
9-
const NOTION_TOKEN_V2 = core.getInput('token_v2');
10-
let id = core.getInput('database_id').replace(/-/g, '');
11-
const databaseId = `${id.substr(0, 8)}-${id.substr(8, 4)}-${id.substr(
12-
12,
13-
4
14-
)}-${id.substr(16, 4)}-${id.substr(20)}`;
15-
16-
const headers: IRequestOptions['headers'] = {
17-
Accept: 'application/json',
18-
'Content-Type': 'application/json',
19-
cookie: `token_v2=${NOTION_TOKEN_V2}`
20-
};
21-
22-
const http = new HttpClient(undefined, undefined, {
23-
headers
24-
});
25-
26-
const collectionView = await ActionUtils.fetchData<TCollectionBlock>(
27-
databaseId,
28-
'block',
29-
http
30-
);
31-
core.info('Fetched database');
32-
33-
const collection_id = collectionView.collection_id;
34-
const collection = await ActionUtils.fetchData<ICollection>(
35-
collection_id,
36-
'collection',
37-
http
38-
);
39-
40-
core.info('Fetched collection');
41-
42-
const response = await http.post(
43-
`https://www.notion.so/api/v3/queryCollection`,
44-
JSON.stringify({
45-
collection: {
46-
id: collection_id,
47-
spaceId: collectionView.space_id
48-
},
49-
collectionView: {
50-
id: collectionView.view_ids[0],
51-
spaceId: collectionView.space_id
52-
},
53-
loader: {
54-
type: 'reducer',
55-
reducers: {
56-
collection_group_results: {
57-
type: 'results'
58-
}
9+
try {
10+
const NOTION_TOKEN_V2 = core.getInput('token_v2');
11+
let id = core.getInput('database_id').replace(/-/g, '');
12+
const databaseId = `${id.substr(0, 8)}-${id.substr(8, 4)}-${id.substr(
13+
12,
14+
4
15+
)}-${id.substr(16, 4)}-${id.substr(20)}`;
16+
17+
const headers: IRequestOptions['headers'] = {
18+
Accept: 'application/json',
19+
'Content-Type': 'application/json',
20+
cookie: `token_v2=${NOTION_TOKEN_V2}`
21+
};
22+
23+
const http = new HttpClient(undefined, undefined, {
24+
headers
25+
});
26+
27+
const collectionView = await ActionUtils.fetchData<TCollectionBlock>(
28+
databaseId,
29+
'block',
30+
http
31+
);
32+
core.info('Fetched database');
33+
34+
const collection_id = collectionView.collection_id;
35+
const collection = await ActionUtils.fetchData<ICollection>(
36+
collection_id,
37+
'collection',
38+
http
39+
);
40+
41+
core.info('Fetched collection');
42+
43+
const response = await http.post(
44+
`https://www.notion.so/api/v3/queryCollection`,
45+
JSON.stringify({
46+
collection: {
47+
id: collection_id,
48+
spaceId: collectionView.space_id
5949
},
60-
searchQuery: '',
61-
userTimeZone: 'Asia/Dhaka'
62-
}
63-
})
64-
);
65-
66-
const { recordMap } = JSON.parse(await response.readBody()) as {
67-
recordMap: RecordMap;
68-
};
69-
70-
core.info('Fetched rows');
71-
const { schema } = collection;
72-
const [
73-
category_schema_entry,
74-
color_schema_entry
75-
] = ActionUtils.getSchemaEntries(schema);
76-
77-
const rows = ActionUtils.modifyRows(recordMap, databaseId);
78-
const categories_map = ActionUtils.constructCategoriesMap(
79-
category_schema_entry[1]
80-
);
81-
ActionUtils.populateCategoriesMapItems(
82-
rows,
83-
category_schema_entry[0],
84-
categories_map
85-
);
86-
87-
const README_PATH = `${process.env.GITHUB_WORKSPACE}/README.md`;
88-
core.info(`Reading from ${README_PATH}`);
89-
90-
const readmeLines = fs.readFileSync(README_PATH, 'utf-8').split('\n');
91-
92-
const [startIdx, endIdx] = ActionUtils.checkForSections(readmeLines);
93-
const newLines = ActionUtils.constructNewContents(
94-
categories_map,
95-
color_schema_entry[0]
96-
);
97-
98-
const finalLines = [
99-
...readmeLines.slice(0, startIdx + 1),
100-
...newLines,
101-
...readmeLines.slice(endIdx)
102-
];
103-
104-
core.info(`Writing to ${README_PATH}`);
105-
106-
fs.writeFileSync(README_PATH, finalLines.join('\n'), 'utf-8');
107-
await ActionUtils.commitFile();
50+
collectionView: {
51+
id: collectionView.view_ids[0],
52+
spaceId: collectionView.space_id
53+
},
54+
loader: {
55+
type: 'reducer',
56+
reducers: {
57+
collection_group_results: {
58+
type: 'results'
59+
}
60+
},
61+
searchQuery: '',
62+
userTimeZone: 'Asia/Dhaka'
63+
}
64+
})
65+
);
66+
67+
const { recordMap } = JSON.parse(await response.readBody()) as {
68+
recordMap: RecordMap;
69+
};
70+
71+
core.info('Fetched rows');
72+
const { schema } = collection;
73+
const [
74+
category_schema_entry,
75+
color_schema_entry
76+
] = ActionUtils.getSchemaEntries(schema);
77+
78+
const rows = ActionUtils.modifyRows(recordMap, databaseId);
79+
const categories_map = ActionUtils.constructCategoriesMap(
80+
category_schema_entry[1]
81+
);
82+
ActionUtils.populateCategoriesMapItems(
83+
rows,
84+
category_schema_entry[0],
85+
categories_map
86+
);
87+
88+
const README_PATH = `${process.env.GITHUB_WORKSPACE}/README.md`;
89+
core.info(`Reading from ${README_PATH}`);
90+
91+
const readmeLines = fs.readFileSync(README_PATH, 'utf-8').split('\n');
92+
93+
const [startIdx, endIdx] = ActionUtils.checkForSections(readmeLines);
94+
const newLines = ActionUtils.constructNewContents(
95+
categories_map,
96+
color_schema_entry[0]
97+
);
98+
99+
const finalLines = [
100+
...readmeLines.slice(0, startIdx + 1),
101+
...newLines,
102+
...readmeLines.slice(endIdx)
103+
];
104+
105+
core.info(`Writing to ${README_PATH}`);
106+
107+
fs.writeFileSync(README_PATH, finalLines.join('\n'), 'utf-8');
108+
await ActionUtils.commitFile();
109+
} catch (err) {
110+
core.setFailed(err.message);
111+
}
108112
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /