chore: replace deprecated String.prototype.substr() (#6333)
* chore: replace deprecated String.prototype.substr() .substr() is deprecated so we replace it with .slice() which works similarily but isn't deprecated Signed-off-by: Tobias Speicher <rootcommander@gmail.com> * refactor: add prefer slice lint rule and fix errors Co-authored-by: erezrokah <erezrokah@users.noreply.github.com>
This commit is contained in:
@ -361,7 +361,7 @@ export default class API {
|
||||
return parseContentKey(contentKey);
|
||||
}
|
||||
|
||||
return parseContentKey(contentKey.substring(this.repo.length + 1));
|
||||
return parseContentKey(contentKey.slice(this.repo.length + 1));
|
||||
}
|
||||
|
||||
checkMetadataRef() {
|
||||
@ -728,7 +728,7 @@ export default class API {
|
||||
|
||||
async migrateToVersion1(pullRequest: GitHubPull, metadata: Metadata) {
|
||||
// hard code key/branch generation logic to ignore future changes
|
||||
const oldContentKey = pullRequest.head.ref.substring(`cms/`.length);
|
||||
const oldContentKey = pullRequest.head.ref.slice(`cms/`.length);
|
||||
const newContentKey = `${metadata.collection}/${oldContentKey}`;
|
||||
const newBranchName = `cms/${newContentKey}`;
|
||||
|
||||
@ -765,7 +765,7 @@ export default class API {
|
||||
async migrateToPullRequestLabels(pullRequest: GitHubPull, metadata: Metadata) {
|
||||
await this.setPullRequestStatus(pullRequest, metadata.status);
|
||||
|
||||
const contentKey = pullRequest.head.ref.substring(`cms/`.length);
|
||||
const contentKey = pullRequest.head.ref.slice(`cms/`.length);
|
||||
await this.deleteMetadata(contentKey);
|
||||
}
|
||||
|
||||
@ -829,7 +829,7 @@ export default class API {
|
||||
// open authoring branches can exist without a pr
|
||||
const cmsBranches: Octokit.GitListMatchingRefsResponse =
|
||||
await this.getOpenAuthoringBranches();
|
||||
branches = cmsBranches.map(b => b.ref.substring('refs/heads/'.length));
|
||||
branches = cmsBranches.map(b => b.ref.slice('refs/heads/'.length));
|
||||
// filter irrelevant branches
|
||||
const branchesWithFilter = await Promise.all(
|
||||
branches.map(b => this.filterOpenAuthoringBranches(b)),
|
||||
|
@ -11,7 +11,7 @@ describe('github API', () => {
|
||||
|
||||
function mockAPI(api, responses) {
|
||||
api.request = jest.fn().mockImplementation((path, options = {}) => {
|
||||
const normalizedPath = path.indexOf('?') !== -1 ? path.substr(0, path.indexOf('?')) : path;
|
||||
const normalizedPath = path.indexOf('?') !== -1 ? path.slice(0, path.indexOf('?')) : path;
|
||||
const response = responses[normalizedPath];
|
||||
return typeof response === 'function'
|
||||
? Promise.resolve(response(options))
|
||||
|
Reference in New Issue
Block a user