-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmetadata.jsonc
More file actions
60 lines (45 loc) · 1.98 KB
/
metadata.jsonc
File metadata and controls
60 lines (45 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const fetch = require('node-fetch');
const fs = require('fs');
const { execSync } = require('child_process');
async function updateMetadata() {
// Get repository URL from git config
const remoteUrl = execSync('git config --get remote.origin.url').toString().trim();
// Parse owner/repo from URL
const urlRegex = /github\.com[:\/]([^\/]+)\/([^\.]+)(\.git)?/;
const match = remoteUrl.match(urlRegex);
if (!match) {
console.error('Could not parse GitHub repository URL');
return;
}
const [, owner, repo] = match;
// Fetch repository metadata from GitHub API
const response = await fetch(`https://api.github.com/repos/${owner}/${repo}`, {
headers: {
'Accept': 'application/vnd.github+json',
'Authorization': process.env.GITHUB_TOKEN ? `Bearer ${process.env.GITHUB_TOKEN}` : '',
}
});
if (!response.ok) {
console.error(`GitHub API error: ${response.status}`);
return;
}
const repoData = await response.json();
// Read current metadata template
const metadataTemplate = JSON.parse(fs.readFileSync('metadata_template.json', 'utf8'));
// Update fields with repository data
metadataTemplate.title = repoData.name;
metadataTemplate.description = repoData.description || metadataTemplate.description;
metadataTemplate.version = repoData.pushed_at ? new Date(repoData.pushed_at).toISOString().split('T')[0] : metadataTemplate.version;
// Update keywords with topics
if (repoData.topics && repoData.topics.length > 0) {
metadataTemplate.keywords = repoData.topics;
}
// Update related identifier
if (metadataTemplate.related_identifiers && metadataTemplate.related_identifiers.length > 0) {
metadataTemplate.related_identifiers[0].identifier = repoData.html_url;
}
// Write updated metadata back to file
fs.writeFileSync('CITATION.cff', JSON.stringify(metadataTemplate, null, 2));
console.log('Metadata successfully updated with repository information');
}
updateMetadata().catch(console.error);