-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice.bal
39 lines (30 loc) · 1010 Bytes
/
service.bal
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
import ballerinax/github;
import ballerina/http;
type Repo record {
string name;
int star;
};
configurable string gitconfig = ?;
# A service representing a network-accessible API
# bound to port `9090`.
service / on new http:Listener(9090) {
# + return - string name with hello message or error
resource function get gitStarts() returns Repo[]|error {
// Send a response back to the caller.
github:Client githubEp = check new (config = {
auth: {
token: gitconfig
}
});
stream<github:Repository, error?> getRepositoriesResponse = check githubEp->getRepositories();
Repo[]|error? repos = from var item in getRepositoriesResponse
where item is github:Repository
order by item.stargazerCount descending
limit 5
select {
name: item.name,
star: item.stargazerCount?: 0
};
return repos?:[];
}
}