-
Notifications
You must be signed in to change notification settings - Fork 31
/
add_contractors.js
112 lines (84 loc) · 2.99 KB
/
add_contractors.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
const TerminusClient = require("@terminusdb/terminusdb-client");
// TODO: Change teamname and username
const teamName = "yourTeam"
const username = "yourUser"
const client = new TerminusClient.WOQLClient(
`https://cloud.terminusdb.com/${teamName}/`,
{ user: username, organization: teamName , db:"GettingStartedDB" }
);
//Assign your key to environment variable TERMINUSDB_ACCESS_TOKEN
client.setApiKey(process.env.TERMINUSDB_ACCESS_TOKEN);
const getCommitHistory = async (branch) => {
const woqlLib = TerminusClient.WOQL;
const commitQuery = woqlLib.lib().commits(branch);
const res = await client.query(commitQuery);
console.log(res.bindings);
return res.bindings
};
const addContractors = async () => {
const rhys = {
"@type": "Employee",
employee_id: "006",
name: "Rhys Arnold",
title: "UX Designer",
team: "IT",
contact_number: "078 3951 7569",
address: {
"@type": "Address",
postcode: "DG4 2ZQ",
street: "Helland Bridge",
street_num: 1,
town: "Ulzieside",
},
};
const maya = {
"@type": "Employee",
employee_id: "007",
name: "Maya O'Brien",
title: "Creative Content Creator",
team: "Marketing",
contact_number: "078 1788 9177",
address: {
"@type": "Address",
postcode: "GU3 3AF",
street: "Tadcaster Rd",
street_num: 24,
town: "Pitch Place",
},
};
await client.addDocument([rhys, maya],{},"","Adding contractors");
};
const runScript = async () => {
try{
const defaultBranches = await client.getBranches();
console.log("Default Branches: ", defaultBranches);
// Create new contractor branch
await client.branch("contractors");
console.log("Branch created successfully!")
const newBranches = await client.getBranches();
console.log("New Branches: ", newBranches);
// checkout to new branch contractors
client.checkout("contractors");
await addContractors();
console.log("Added Contractors successfully!")
console.log("Main Commit History: ")
await getCommitHistory("main");
console.log("Contractors Commit History: ")
await getCommitHistory("contractors");
client.checkout("main");
await client.rebase({rebase_from: `${teamName}/GettingStartedDB/local/branch/contractors/`, message: "Merging from contractors" , author: "USer"});
console.log("Rebase done successfully!");
const mainCommits = await getCommitHistory("main");
//We would like to keep the commits up to the `Adding Ethan` one
const mainCommitObj = mainCommits.find(item=>item["Message"]["@value"] === 'Adding ethan')
const oldMainCommitID = mainCommitObj['Commit ID']['@value']
console.log('Main Commit ID',oldMainCommitID )
await client.resetBranch("main", oldMainCommitID);
console.log("Reset done successfully!");
console.log("Main Commit History: ")
await getCommitHistory("main");
}catch(err){
console.log(err.message)
}
}
runScript();