forked from ndu2/gitlab-time-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgtt-sync.js
More file actions
executable file
·46 lines (40 loc) · 1.45 KB
/
gtt-sync.js
File metadata and controls
executable file
·46 lines (40 loc) · 1.45 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
import moment from 'moment';
import {Command} from 'commander';
import Config from './include/file-config.js';
import Cli from './include/cli.js';
import Tasks from './include/tasks.js';
import Owner from './models/owner.js';
function sync() {
const sync = new Command('sync', 'sync local time records to GitLab')
.option('--url <url>', 'URL to GitLabs API')
.option('--token <token>', 'API access token')
.option('--verbose', 'show verbose output')
.action((options, program) => {
Cli.verbose = program.opts().verbose;
let config = new Config(process.cwd())
.set('url', program.opts().url)
.set('token', program.opts().token),
tasks = new Tasks(config),
owner = new Owner(config);
tasks.syncInit()
.then(() => tasks.sync.frames.length === 0 ? process.exit(0) : null)
.then(() => owner.authorized())
.catch(e => Cli.x(`Invalid access token!`, e))
.then(() => {
Cli.bar(`${Cli.fetch} Fetching or creating issues & merge requests...`, tasks.sync.frames.length);
return tasks.syncResolve(Cli.advance);
})
.then(() => {
Cli.bar(`${Cli.process} Processing issues & merge requests...`, tasks.sync.frames.length);
return tasks.syncDetails(Cli.advance);
})
.then(() => {
Cli.bar(`${Cli.update} Syncing time records...`, tasks.sync.frames.length);
return tasks.syncUpdate(Cli.advance)
})
.catch(error => Cli.x(error));
}
);
return sync;
}
export default sync;