forked from gh-conf/upstream-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
43 lines (30 loc) · 1.09 KB
/
index.js
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
const { readConf } = require('@gh-conf/gh-conf-read');
const { writeConf } = require('@gh-conf/gh-conf-write');
const { ParentRepo } = require('@gh-conf/gh-api');
const { UserRepo } = require('@gh-conf/gh-conf-parse');
const { Formatter, Validator } = require('./lib');
const upstream = async (currentPath) => {
try {
// Read config file content
const configContent = await readConf(`${currentPath}`);
// Check if upstream already added
if (Validator.isUptreamed(configContent)) {
throw new Error('Upstream already configured');
}
// Fetch current repository usernanme and repository name
const { username, repository } = UserRepo();
// Getting parent repo url
const url = await ParentRepo(username, repository);
if (!url) {
throw new Error('Not a forked repository!!!');
}
// Formatting Parent Repo URL
const upstreamData = Formatter(url);
// Writting updated config
return await writeConf(`${currentPath}`, configContent + upstreamData);
} catch (err) {
console.error(err);
throw err;
}
};
module.exports = upstream;