Skip to content

Commit 32ab35f

Browse files
Merge pull request #14 from centralnicgroup-opensource/RSRMID-1616-Changemanagement-Notification-Extending-Further-fix
fix(payloadutils.js): resolved repository URL issue with trailing ".git"
2 parents 116e75c + c383fc3 commit 32ab35f

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

lib/payloadUtils.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,20 @@ const readPackageJson = async () => {
4747
const { repository, name } = JSON.parse(await fs.readFile('package.json', 'utf8'));
4848

4949
const [prefix, repo] = repository?.split(':') || [];
50-
const repoUrl = (prefix === 'github' && repo) ? `https://github.com/${repo}` : 'Invalid GitHub string format';
50+
let repoUrl;
51+
if (prefix === 'github' && repo) {
52+
// Check if the repository name ends with '.git' and remove it
53+
const sanitizedRepo = repo.endsWith('.git') ? repo.slice(0, -4) : repo;
5154

55+
// Construct the GitHub URL
56+
repoUrl = `https://github.com/${sanitizedRepo}`;
57+
} else {
58+
// Handle the case of an invalid GitHub string format
59+
console.error('Invalid GitHub string format. Please provide a valid GitHub repository string in the format "github:username/repo.git".');
60+
61+
// Optionally, set repoUrl to a default value or handle the error accordingly
62+
repoUrl = undefined;
63+
}
5264
return { projectName: name || "", repoUrl };
5365
} catch (error) {
5466
console.error('Error reading or parsing package.json file:', error);

0 commit comments

Comments
 (0)