-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
138 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
const { analyzeDirectory } = require('./analyze'); | ||
const { getRepoDetails } = require('./repoDetails'); | ||
const { generateYamlSchema } = require('./yamlGenerator'); | ||
|
||
function run(targetDir, repository, outputPath) { | ||
const events = analyzeDirectory(targetDir, repository); | ||
generateYamlSchema(events, outputPath); | ||
function run(targetDir, outputPath) { | ||
const events = analyzeDirectory(targetDir); | ||
const repoDetails = getRepoDetails(targetDir); | ||
generateYamlSchema(events, repoDetails, outputPath); | ||
} | ||
|
||
module.exports = { run }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
const { execSync } = require('child_process'); | ||
|
||
function getRepositoryUrl(targetDir) { | ||
try { | ||
const repoUrl = execSync('git config --get remote.origin.url', { cwd: targetDir, encoding: 'utf8' }); | ||
return repoUrl.trim(); | ||
} catch (error) { | ||
console.warn('Could not determine repository URL. Will exclude.'); | ||
return null; | ||
} | ||
} | ||
|
||
function getCommitHash(targetDir) { | ||
try { | ||
const commitHash = execSync('git rev-parse HEAD', { cwd: targetDir, encoding: 'utf8' }); | ||
return commitHash.trim(); | ||
} catch (error) { | ||
console.warn('Could not determine latest commit hash. Will exclude.'); | ||
return null; | ||
} | ||
} | ||
|
||
function getCommitTimestamp(targetDir, commitHash) { | ||
try { | ||
const commitTimestamp = execSync(`git --no-pager show -s --format=%ct ${commitHash}`, { cwd: targetDir, encoding: 'utf8' }); | ||
const unixTimeSeconds = commitTimestamp.trim(); | ||
return new Date(unixTimeSeconds * 1000); | ||
} catch (error) { | ||
console.warn('Could not retrieve commit timestamp. Using current timestamp as default.') | ||
return new Date(); | ||
} | ||
} | ||
|
||
function pad(n) { | ||
return n<10 ? '0'+n : n | ||
} | ||
|
||
function toISODateString(date) { | ||
return date.getUTCFullYear()+'-' | ||
+ pad(date.getUTCMonth()+1)+'-' | ||
+ pad(date.getUTCDate())+'T' | ||
+ pad(date.getUTCHours())+':' | ||
+ pad(date.getUTCMinutes())+':' | ||
+ pad(date.getUTCSeconds())+'Z' | ||
} | ||
|
||
function getRepoDetails(targetDir) { | ||
const repoUrl = getRepositoryUrl(targetDir); | ||
const commitHash = getCommitHash(targetDir); | ||
const commitEpochTime = getCommitTimestamp(targetDir, commitHash); | ||
const commitTimestamp = toISODateString(commitEpochTime); | ||
|
||
const repoDetails = {}; | ||
if (!!repoUrl) repoDetails.repository = repoUrl; | ||
if (!!commitHash) repoDetails.commit = commitHash; | ||
repoDetails.timestamp = commitTimestamp | ||
|
||
return repoDetails; | ||
} | ||
|
||
module.exports = { getRepoDetails }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters