Skip to content

Commit b114d77

Browse files
committed
fix/ICE-1010-improvement: merge
1 parent 209d934 commit b114d77

File tree

32 files changed

+107116
-74186
lines changed

32 files changed

+107116
-74186
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ repos:
3535
# Standard pre-commit-hooks for general all-purpose formatting and validation
3636
# -----------------------------
3737
- repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook
38-
rev: v9.16.0
38+
rev: v9.17.0
3939
hooks:
4040
- id: commitlint
4141
stages: [commit-msg]

common/localize-mirrored-repo.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
const { execSync } = require('child_process');
4+
const logger = require('./logger.js');
5+
6+
function replaceContentAndCommit() {
7+
// Replace all occurrences of opencepk/opencepk-module-ghactions-common with in .github/workflows/*.yml
8+
logger.info(
9+
'Replacing opencepk/opencepk-module-ghactions-common in .github/workflows/*.yml',
10+
);
11+
const workflowDir = path.join('.github', 'workflows');
12+
const files = fs.readdirSync(workflowDir);
13+
files.forEach(file => {
14+
const filePath = path.join(workflowDir, file);
15+
if (filePath.endsWith('.yml') || filePath.endsWith('.yaml')) {
16+
let content = fs.readFileSync(filePath, 'utf8');
17+
logger.info(
18+
`Replacing content from opencepk/opencepk-module-ghactions-common to {{internal repo owner}}/opencepk-module-ghactions-common in ${filePath}`,
19+
);
20+
content = content.replace(
21+
/opencepk\/opencepk-module-ghactions-common/g,
22+
'tucowsinc/opencepk-module-ghactions-common',
23+
);
24+
logger.info(
25+
`Replacing content from opencepk/opencepk-projects-hub to {{internal repo owner}}/cepk-projects-hub in ${filePath}`,
26+
);
27+
content = content.replace(
28+
/repo: 'opencepk\/opencepk-projects-hub'/g,
29+
"repo: 'tucowsinc/cepk-projects-hub'",
30+
);
31+
fs.writeFileSync(filePath, content);
32+
}
33+
});
34+
35+
// Commit the changes after replacement
36+
logger.info('Committing changes after replacement');
37+
execSync('git add .github/workflows');
38+
try {
39+
execSync(
40+
'git commit -m "chores/cleanup: Replace opencepk with internal repo owner in workflow files"',
41+
);
42+
} catch (error) {
43+
if (error.message.includes('nothing to commit')) {
44+
logger.info('No changes to commit in workflow files. Proceeding...');
45+
} else {
46+
throw error;
47+
}
48+
}
49+
50+
// Replace all occurrences of git@github.com:opencepk with git@github.com:{{internal repo owner}} in .pre-commit-config.yaml
51+
logger.info(
52+
'Replacing git@github.com:opencepk in .pre-commit-config.yaml',
53+
);
54+
const preCommitConfigPath = '.pre-commit-config.yaml';
55+
if (fs.existsSync(preCommitConfigPath)) {
56+
let preCommitContent = fs.readFileSync(preCommitConfigPath, 'utf8');
57+
preCommitContent = preCommitContent.replace(
58+
/git@github.com:opencepk/g,
59+
'git@github.com:tucowsinc',
60+
);
61+
fs.writeFileSync(preCommitConfigPath, preCommitContent);
62+
63+
// Commit the changes after replacement
64+
logger.info(
65+
'chores/cleanup: Committing changes to .pre-commit-config.yaml',
66+
);
67+
execSync('git add .pre-commit-config.yaml');
68+
try {
69+
logger.info('Committing changes to .pre-commit-config.yaml');
70+
execSync(
71+
'git commit -m "chores/update: Replace org opencepk in .pre-commit-config.yaml"',
72+
);
73+
} catch (error) {
74+
logger.warn(`${JSON.stringify(error)}`);
75+
logger.info(
76+
'No changes to commit in .pre-commit-config.yaml. Proceeding...',
77+
);
78+
}
79+
} else {
80+
logger.info(
81+
'.pre-commit-config.yaml does not exist, skipping replacement.',
82+
);
83+
}
84+
}
85+
86+
module.exports = { replaceContentAndCommit };

common/logger.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const core = require('@actions/core');
66
const red = '\x1b[31m';
77
const blue = '\x1b[34m';
88
const green = '\x1b[32m';
9+
const yellow = '\x1b[33m';
910
const reset = '\x1b[0m';
1011

1112
/**
@@ -24,6 +25,10 @@ function error(message) {
2425
* @memberof logger
2526
* @param {string} message - The informational message to log.
2627
*/
28+
function warn(message) {
29+
core.warning(`${yellow}${message}${reset}`);
30+
}
31+
2732
function info(message) {
2833
core.info(`${blue}${message}${reset}`);
2934
}
@@ -50,6 +55,7 @@ function setFailed(message) {
5055

5156
module.exports = {
5257
error,
58+
warn,
5359
info,
5460
debug,
5561
setFailed,

0 commit comments

Comments
 (0)