Fixing stringify of hash arguments (#2057)

This commit is contained in:
Justin Dalrymple 2021-09-04 01:19:07 -04:00 committed by GitHub
parent 30089992fe
commit f19174c7cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 35 additions and 6 deletions

View File

@ -66,6 +66,7 @@
- [Sudo](#sudo)
- [Custom Request Libraries](#custom-request-libraries)
- [Misc](#misc)
- [Debugging](#debugging)
- [Development](#development)
- [Testing](#testing)
- [Contributors](#contributors)
@ -497,6 +498,9 @@ let bufferedData = await api.Jobs.downloadLatestArtifactFile(project.id, 'test',
fs.writeFileSync('test.zip', bufferedData);
```
## Debugging
Depending on the library used, the full information about the request error can be a bit obfuscated. Ideally, the entire information is returned from Ky (browser) or Got (nodejs) however for simplicity, a description property is added to the error object that has the error message attached. Simply look for e.description to have a better idea of what the error actually is.
## Development
To get this running locally rather than from your `node_modules` folder:

View File

@ -61,20 +61,47 @@ export interface AllMergeRequestsOptions {
view?: string;
labels?: string | Array<string>;
withLabelsDetails?: boolean;
withMergeStatusRecheck?: boolean;
createdAfter?: string;
createdBefore?: string;
updatedBefore?: string;
updatedAfter?: string;
scope?: 'created_by_me' | 'assigned_to_me' | 'all';
authorId?: number;
authorUsername?: string;
asigneeId?: number;
assigneeUsername?: string;
approverIds?: Array<number>;
approvedByIds?: Array<number>;
reviewerId?: number;
reviewerUsername?: string;
myReactionEmoji?: string;
sourceBranch?: string;
targetBranch?: string;
in?: string;
wip?: string;
iids?: number[];
mergeCommitMessage?: string;
squashCommitMessage?: string;
squash?: boolean;
shouldRemoveSourceBranch?: boolean;
mergeWhenPipelineSucceeds?: boolean;
sha?: string;
search?: string;
not?: {
labels?: string | Array<string>;
milestone?: string;
authorId?: number;
authorUsername?: string;
assigneeId?: number;
assigneeUsername?: string;
reviewerId?: number;
reviewerUsername?: string;
myReactionEmoji?: string;
};
environment?: string;
deployedBefore?: string;
deployedAfter?: string;
}
// Response Schemas

View File

@ -10,7 +10,7 @@
},
"dependencies": {
"form-data": "^4.0.0",
"query-string": "^7.0.0",
"qs": "^6.10.1",
"xcase": "^2.0.1"
},
"devDependencies": {

View File

@ -1,6 +1,6 @@
import { decamelizeKeys } from 'xcase';
import FormData from 'form-data';
import { stringify } from 'query-string';
import { stringify } from 'qs';
// Types
export interface Constructable<T = any> {
@ -42,8 +42,6 @@ export type DefaultRequestReturn = {
export function formatQuery(params: Record<string, unknown> = {}): string {
const decamelized = decamelizeKeys(params);
if (decamelized.not) decamelized.not = JSON.stringify(decamelized.not);
return stringify(decamelized, { arrayFormat: 'bracket' });
}

View File

@ -257,6 +257,6 @@ describe('formatQuery', () => {
it('should decamelize sub keys in not property and stringify the object', () => {
const string = formatQuery({ test: 6, not: { test: 7 } });
expect(string).toBe('not=%7B%22test%22%3A7%7D&test=6');
expect(string).toBe('test=6&not%5Btest%5D=7');
});
});

View File

@ -7925,7 +7925,7 @@ q@^1.5.1:
resolved "https://registry.yarnpkg.com/q/-/q-1.5.1.tgz#7e32f75b41381291d04611f1bf14109ac00651d7"
integrity sha1-fjL3W0E4EpHQRhHxvxQQmsAGUdc=
qs@^6.9.4:
qs@^6.10.1, qs@^6.9.4:
version "6.10.1"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.10.1.tgz#4931482fa8d647a5aab799c5271d2133b981fb6a"
integrity sha512-M528Hph6wsSVOBiYUnGf+K/7w0hNshs/duGsNXPUCLH5XAqjEtiPGwNONLV0tBH8NoGb0mvD5JubnUTrujKDTg==