refactor(stack-overflow-backend): use official default request parameters
Signed-off-by: Camila Belo <camilaibs@gmail.com>
This commit is contained in:
@@ -3,3 +3,5 @@
|
||||
---
|
||||
|
||||
Migrate package to the new Frontend system, the new module is distributed with a `/alpha` subpath.
|
||||
|
||||
The search collator `requestParams` option is optional now, so its defaults to `{ order: 'desc', sort: 'activity', site: 'stackoverflow' }` as done in the `Try It` section on the [official Stack Overflow API documentation](https://api.stackexchange.com/docs/questions).
|
||||
|
||||
@@ -45,7 +45,7 @@ This stack overflow backend plugin is primarily responsible for the following:
|
||||
|
||||
Before you are able to start index stack overflow questions to search, you need to go through the [search getting started guide](https://backstage.io/docs/features/search/getting-started).
|
||||
|
||||
When you have your `packages/backend/src/plugins/search.ts` file ready to make modifications, add the following code snippet to add the `StackOverflowQuestionsCollatorFactory`. Note that you can modify the `requestParams`.
|
||||
When you have your `packages/backend/src/plugins/search.ts` file ready to make modifications, add the following code snippet to add the `StackOverflowQuestionsCollatorFactory`. Note that you can optionally modify the `requestParams`, otherwise it will defaults to `{ order: 'desc', sort: 'activity', site: 'stackoverflow' }` as done in the `Try It` section on the [official Stack Overflow API documentation](https://api.stackexchange.com/docs/questions).
|
||||
|
||||
> Note: if your `baseUrl` is set to the external stack overflow api `https://api.stackexchange.com/2.2`, you can find optional and required parameters under the official API documentation under [`Usage of /questions GET`](https://api.stackexchange.com/docs/questions)
|
||||
|
||||
|
||||
@@ -81,10 +81,13 @@ export class StackOverflowQuestionsCollatorFactory
|
||||
this.apiAccessToken = options.apiAccessToken;
|
||||
this.teamName = options.teamName;
|
||||
this.maxPage = options.maxPage;
|
||||
// Sets the same default request parameters as the official API documentation
|
||||
// See https://api.stackexchange.com/docs/questions
|
||||
this.requestParams = options.requestParams ?? {
|
||||
tagged: ['backstage'],
|
||||
order: 'desc',
|
||||
sort: 'activity',
|
||||
site: 'stackoverflow',
|
||||
pagesize: 100,
|
||||
...(options.requestParams ?? {}),
|
||||
};
|
||||
this.logger = options.logger.child({ documentType: this.type });
|
||||
}
|
||||
@@ -102,10 +105,9 @@ export class StackOverflowQuestionsCollatorFactory
|
||||
config.getOptionalString('stackoverflow.baseUrl') ||
|
||||
'https://api.stackexchange.com/2.3';
|
||||
const maxPage = options.maxPage || 100;
|
||||
const requestParams =
|
||||
config.getOptional<StackOverflowQuestionsRequestParams>(
|
||||
'stackoverflow.requestParams',
|
||||
);
|
||||
const requestParams = config
|
||||
.getOptionalConfig('stackoverflow.requestParams')
|
||||
?.get<StackOverflowQuestionsRequestParams>();
|
||||
return new StackOverflowQuestionsCollatorFactory({
|
||||
baseUrl,
|
||||
maxPage,
|
||||
@@ -184,7 +186,7 @@ export class StackOverflowQuestionsCollatorFactory
|
||||
);
|
||||
|
||||
const data = await res.json();
|
||||
for (const question of data.items) {
|
||||
for (const question of data.items ?? []) {
|
||||
yield {
|
||||
title: question.title,
|
||||
location: question.link,
|
||||
|
||||
Reference in New Issue
Block a user