Skip to content

Commit 795723f

Browse files
authored
Merge branch 'main' into refactor/add-typescript-to-cypress
2 parents 4e89345 + 32687e8 commit 795723f

File tree

7 files changed

+104
-54
lines changed

7 files changed

+104
-54
lines changed

.github/workflows/deploy-eng.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ jobs:
5353
LOCALE_FOR_UI: ${{ matrix.languages }}
5454
LOCALE_FOR_GHOST: ${{ matrix.languages }}
5555

56+
DO_NOT_FETCH_FROM_GHOST: true
57+
5658
steps:
5759
- name: Checkout source code
5860
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4

config/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ module.exports = Object.assign(
150150
eleventyEnv: eleventyEnv || 'dev',
151151
hashnodeAPIURL:
152152
!hashnodeAPIURL || hashnodeAPIURL === 'api_url_from_hashnode_dashboard'
153-
? ''
153+
? 'https://gql.hashnode.com'
154154
: hashnodeAPIURL,
155155
chatWebhookKey:
156156
!chatWebhookKey ||

package-lock.json

Lines changed: 28 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
"algoliasearch": "4.24.0",
7373
"clean-css": "5.3.3",
7474
"cross-env": "7.0.3",
75-
"cypress": "13.13.3",
75+
"cypress": "13.14.1",
7676
"dayjs": "1.11.13",
7777
"dotenv": "16.4.5",
7878
"eslint": "8.57.0",
@@ -91,7 +91,7 @@
9191
"js-yaml": "4.1.0",
9292
"jsdom": "24.1.3",
9393
"libxmljs": "1.0.11",
94-
"lint-staged": "15.2.9",
94+
"lint-staged": "15.2.10",
9595
"lodash": "4.17.21",
9696
"md5": "2.3.0",
9797
"node-cache": "5.1.2",

sample.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,6 @@ POSTS_PER_PAGE=25
9191
SITE_DOMAIN=localhost:8080
9292
LOCALE_FOR_UI=italian
9393
LOCALE_FOR_GHOST=italian
94+
95+
# HASHNODE_DEBUG_MODE_FIRST_PAGE_ONLY=true
96+
# DO_NOT_FETCH_FROM_GHOST=true

utils/ghost/fetch-from-ghost.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ const fetchFromGhost = async endpoint => {
1111
limit: 200
1212
};
1313

14+
if (process.env.DO_NOT_FETCH_FROM_GHOST) {
15+
console.log(
16+
'DO_NOT_FETCH_FROM_GHOST is active. This is likely because Ghost is not available for this environment.'
17+
);
18+
return [];
19+
}
20+
1421
while (currPage && currPage <= lastPage) {
1522
const ghostRes = await ghostAPI[endpoint]
1623
.browse({

utils/hashnode/fetch-from-hashnode.js

Lines changed: 61 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
const { gql, request } = require('graphql-request');
22
const { hashnodeHost } = require('../api');
3-
const { eleventyEnv, currentLocale_i18n } = require('../../config');
3+
const {
4+
eleventyEnv,
5+
currentLocale_i18n,
6+
hashnodeAPIURL
7+
} = require('../../config');
48
const wait = require('../wait');
59

610
const fetchFromHashnode = async contentType => {
@@ -86,28 +90,62 @@ const fetchFromHashnode = async contentType => {
8690
let hasNextPage = true;
8791

8892
while (hasNextPage) {
89-
const res =
90-
eleventyEnv === 'ci' && currentLocale_i18n === 'english'
91-
? require(`../../cypress/fixtures/mock-hashnode-${contentType}.json`)
92-
: await request(process.env.HASHNODE_API_URL, query, {
93-
host: hashnodeHost,
94-
first: 20,
95-
after
96-
});
97-
98-
const resData =
99-
res.publication[fieldName]?.edges.map(({ node }) => node) || [];
100-
const pageInfo = res.publication[fieldName]?.pageInfo;
101-
102-
if (resData.length > 0)
103-
console.log(
104-
`Fetched Hashnode ${contentType} ${pageInfo.endCursor}... and using ${process.memoryUsage.rss() / 1024 / 1024} MB of memory`
105-
);
106-
107-
after = pageInfo.endCursor;
108-
hasNextPage = pageInfo.hasNextPage;
109-
110-
data.push(...resData);
93+
let retries = 3;
94+
let success = false;
95+
96+
while (retries > 0 && !success) {
97+
try {
98+
const res =
99+
eleventyEnv === 'ci' && currentLocale_i18n === 'english'
100+
? require(
101+
`../../cypress/fixtures/mock-hashnode-${contentType}.json`
102+
)
103+
: await request(hashnodeAPIURL, query, {
104+
host: hashnodeHost,
105+
first: 20,
106+
after
107+
});
108+
109+
const resData =
110+
res.publication[fieldName]?.edges.map(({ node }) => node) || [];
111+
const pageInfo = res.publication[fieldName]?.pageInfo;
112+
113+
if (resData.length > 0)
114+
console.log(
115+
`Fetched Hashnode ${contentType} ${pageInfo.endCursor}... and using ${process.memoryUsage.rss() / 1024 / 1024} MB of memory`
116+
);
117+
118+
after = pageInfo.endCursor;
119+
if (process.env.HASHNODE_DEBUG_MODE_FIRST_PAGE_ONLY) {
120+
console.log(
121+
'HASHNODE_DEBUG_MODE_FIRST_PAGE_ONLY is active. Fetching only the first page.'
122+
);
123+
}
124+
125+
hasNextPage =
126+
pageInfo.hasNextPage &&
127+
!process.env.HASHNODE_DEBUG_MODE_FIRST_PAGE_ONLY;
128+
129+
data.push(...resData);
130+
131+
success = true;
132+
} catch (error) {
133+
if (error.message.includes('ECONNRESET') && retries > 1) {
134+
console.log(
135+
`Connection reset error. Retrying... (${retries - 1} attempts left)`
136+
);
137+
retries--;
138+
await wait(10000); // Wait for 10 seconds before retrying
139+
} else {
140+
throw error; // If it's not a connection reset or no more retries, rethrow the error
141+
}
142+
}
143+
}
144+
145+
if (!success) {
146+
console.error('Failed to fetch data after multiple retries');
147+
break;
148+
}
111149

112150
await wait(200);
113151
}

0 commit comments

Comments
 (0)