-
Notifications
You must be signed in to change notification settings - Fork 15
/
frame-handlers.js
172 lines (159 loc) · 4.85 KB
/
frame-handlers.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
var Config = require("./conf")
, Profile = require(Config.root + "/lib/ui/profile")
, Overlap = require("overlap")
, Keypress = require("keypress")
, Box = require("cli-box")
;
var Handlers = module.exports = {};
var Dialog = {
show: function (message) {
var old = Config.cache._currentScreen;
if (!message) {
return Config.cli.update.render("\n" + old, false, {}, false);
}
var box = Box({
w: 50
, h: 5
, marks: {
nw: "╔"
, n: "═"
, ne: "╗"
, e: "║"
, se: "╝"
, s: "═"
, sw: "╚"
, w: "║"
, b: " "
}
}, {
text: message
, stretch: true
, autoEOL: true
, hAlign: "center"
, vAlign: "middle"
});
var newS = Overlap({
who: old
, with: box
, where: {
x: Math.floor(old.split("\n")[0].length / 2 - box.split("\n")[0].length / 2 - 1)
, y: Math.floor(old.split("\n").length / 2 - box.split("\n").length / 2)
}
}).trim();
Config.cli.update.render(newS, false, {}, false);
}
};
Handlers["news-feed"] = {
// Create repository
"C": function () {
Dialog.show("Waiting for user input ...");
Config.promptRunning = true;
var result = {};
while (!(result.name = Config.prompt("Repository name"))) {}
result.description = Config.prompt("Repository description (optional)");
result.homepage = Config.prompt("Repository homepage (optional)");
while (true) {
result.private = Config.prompt("Private repository (y/N)");
if (!result.private || result.private.toLowerCase() === "n") {
result.private = false;
break;
}
if (result.private.toLowerCase() === "y") {
result.private = true;
break;
}
}
Config.promptRunning = false;
if (!result) { return Dialog.show(); }
Dialog.show("Loading...");
Config._github.repos.create(result, function (err, data) {
if (err) { return Dialog.show("Cannot create repository: " + JSON.parse(err.message).message); }
Dialog.show("Repository created at: " + data.ssh_url);
});
}
// Profile
, "P": function () {
Dialog.show("Waiting for user input ...");
Config.promptRunning = true;
var username = Config.prompt("Username");
Config.promptRunning = false;
if (!username) { return Dialog.show(); }
Dialog.show("Loading...");
Profile(username, function (err, progressMsg) {
Dialog.show(err || progressMsg);
}, function (err) {
if (err) {
return Dialog.show(err.message);
}
});
}
// Show issues
, "I": function () {
Dialog.show("Fetching issues...");
require("./ui/user-issues")({
type: "issues"
, ops: {
sort: "updated"
, q: "is:open is:issue assignee:" + Config.username
}
}, function (msg) {
Dialog.show(msg);
});
}
// Show pull requests
, "R": function () {
Dialog.show("Fetching pull requests...");
require("./ui/user-issues")({
type: "pullrequests"
, ops: {
filter: "created"
, sort: "updated"
, state: "open"
}
, ops: {
sort: "updated"
, q: "is:open is:pr author:" + Config.username
}
}, function (msg) {
Dialog.show(msg);
});
}
};
Handlers["profile"] = {
// Show followers
"R": function () {
if (Config.cFrameData.type !== "User") { return; }
Dialog.show("Fetching followers...");
require("./ui/user-list")({
type: "followers"
, user: Config.cFrameData.login
}, function (msg) {
Dialog.show(msg);
});
}
// Show following
, "N": function () {
if (Config.cFrameData.type !== "User") { return; }
Dialog.show("Fetching following...");
require("./ui/user-list")({
type: "following"
, user: Config.cFrameData.login
}, function (msg) {
Dialog.show(msg);
});
}
// Show members
, "M": function () {
if (Config.cFrameData.type !== "Organization") { return; }
Dialog.show("Fetching members...");
require("./ui/user-list")({
type: "members"
, user: Config.cFrameData.login
}, function (msg) {
Dialog.show(msg);
});
}
};
Handlers["user-list"] = {
"P": Handlers["news-feed"].P
};