refactor: convert function expressions to declarations (#4926)

This commit is contained in:
Vladislav Shkodin
2021-02-08 20:01:21 +02:00
committed by GitHub
parent c0236536dd
commit 141a2eba56
241 changed files with 3444 additions and 2933 deletions

View File

@ -129,12 +129,15 @@ type MediaFile = {
path: string;
};
const withCmsLabel = (pr: GitHubPull, cmsLabelPrefix: string) =>
pr.labels.some(l => isCMSLabel(l.name, cmsLabelPrefix));
const withoutCmsLabel = (pr: GitHubPull, cmsLabelPrefix: string) =>
pr.labels.every(l => !isCMSLabel(l.name, cmsLabelPrefix));
function withCmsLabel(pr: GitHubPull, cmsLabelPrefix: string) {
return pr.labels.some(l => isCMSLabel(l.name, cmsLabelPrefix));
}
const getTreeFiles = (files: GitHubCompareFiles) => {
function withoutCmsLabel(pr: GitHubPull, cmsLabelPrefix: string) {
return pr.labels.every(l => !isCMSLabel(l.name, cmsLabelPrefix));
}
function getTreeFiles(files: GitHubCompareFiles) {
const treeFiles = files.reduce((arr, file) => {
if (file.status === 'removed') {
// delete the file
@ -152,7 +155,7 @@ const getTreeFiles = (files: GitHubCompareFiles) => {
}, [] as { sha: string | null; path: string }[]);
return treeFiles;
};
}
export type Diff = {
path: string;
@ -446,7 +449,7 @@ export default class API {
headers: { Accept: 'application/vnd.github.v3.raw' },
};
const errorHandler = (err: Error) => {
function errorHandler(err: Error) {
if (err.message === 'Not Found') {
console.log(
'%c %s does not have metadata',
@ -455,7 +458,7 @@ export default class API {
);
}
throw err;
};
}
if (!this.useOpenAuthoring) {
const result = await this.request(

View File

@ -69,14 +69,14 @@ type GraphQLPullRequest = {
};
};
const transformPullRequest = (pr: GraphQLPullRequest) => {
function transformPullRequest(pr: GraphQLPullRequest) {
return {
...pr,
labels: pr.labels.nodes,
head: { ref: pr.headRefName, sha: pr.headRefOid, repo: { fork: pr.repository.isFork } },
base: { ref: pr.baseRefName, sha: pr.baseRefOid },
};
};
}
type Error = GraphQLError & { type: string };

View File

@ -8,7 +8,7 @@ describe('github API', () => {
jest.resetAllMocks();
});
const mockAPI = (api, responses) => {
function mockAPI(api, responses) {
api.request = jest.fn().mockImplementation((path, options = {}) => {
const normalizedPath = path.indexOf('?') !== -1 ? path.substr(0, path.indexOf('?')) : path;
const response = responses[normalizedPath];
@ -16,7 +16,7 @@ describe('github API', () => {
? Promise.resolve(response(options))
: Promise.reject(new Error(`No response for path '${normalizedPath}'`));
});
};
}
describe('editorialWorkflowGit', () => {
it('should create PR with correct base branch name when publishing with editorial workflow', () => {

View File

@ -62,7 +62,7 @@ export const statues = gql`
${fragments.object}
`;
const buildFilesQuery = (depth = 1) => {
function buildFilesQuery(depth = 1) {
const PLACE_HOLDER = 'PLACE_HOLDER';
let query = oneLine`
...ObjectParts
@ -93,21 +93,23 @@ const buildFilesQuery = (depth = 1) => {
query = query.replace(PLACE_HOLDER, '');
return query;
};
}
export const files = (depth: number) => gql`
query files($owner: String!, $name: String!, $expression: String!) {
repository(owner: $owner, name: $name) {
...RepositoryParts
object(expression: $expression) {
${buildFilesQuery(depth)}
export function files(depth: number) {
return gql`
query files($owner: String!, $name: String!, $expression: String!) {
repository(owner: $owner, name: $name) {
...RepositoryParts
object(expression: $expression) {
${buildFilesQuery(depth)}
}
}
}
}
${fragments.repository}
${fragments.object}
${fragments.fileEntry}
`;
${fragments.repository}
${fragments.object}
${fragments.fileEntry}
`;
}
const branchQueryPart = `
branch: ref(qualifiedName: $qualifiedName) {