Skip to content

Commit

Permalink
Get project friendly names from GitHub
Browse files Browse the repository at this point in the history
  • Loading branch information
rtm516 committed Feb 16, 2024
1 parent 5aca5d4 commit 1bce050
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 4 deletions.
15 changes: 11 additions & 4 deletions monitor.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const fs = require('fs')
const path = require('path')
const axios = require('axios')
const crypto = require('crypto')
const chokidar = require('chokidar')
const { execSync } = require('child_process')

require('log-timestamp')
require('dotenv').config()
Expand Down Expand Up @@ -55,12 +55,19 @@ watcher.on('add', async (filepath) => {
})

async function handleMetadata (folder, metadata) {
const projectFriendly = metadata.project.charAt(0).toUpperCase() + metadata.project.slice(1)
const repoUrl = process.env.ORG + projectFriendly
let projectFriendly = metadata.project.charAt(0).toUpperCase() + metadata.project.slice(1)
let repoUrl = process.env.ORG + projectFriendly
const versionGroup = metadata.version.split('.').slice(0, 2).join('.')
const files = fs.readdirSync(folder).filter(f => f !== 'metadata.json')

console.log(`Project: ${metadata.project}`)
// Use the GitHub API to get the project name if it exists
const repoData = await axios.get(repoUrl.replace('github.com/', 'api.github.com/repos/')).then((res) => res.data).catch((e) => null)
if (repoData && 'name' in repoData) {
projectFriendly = repoData.name
repoUrl = repoData.html_url
}

console.log(`Project: ${projectFriendly} (${metadata.project})`)
console.log(`Version: ${metadata.version}`)
console.log(`Version Group: ${versionGroup}`)
console.log(`Build: ${metadata.id}`)
Expand Down
91 changes: 91 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"standard": "^17.0.0"
},
"dependencies": {
"axios": "^1.6.7",
"chokidar": "^3.5.3",
"dotenv": "^16.0.3",
"gitlog": "^4.0.4",
Expand Down

0 comments on commit 1bce050

Please sign in to comment.