-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
92 lines (91 loc) · 2.58 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
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
require("dotenv").config();
const Axios = require("axios");
const util = require("util");
const axios = Axios.create({
baseURL: "https://vinaymavi-91108825-eval-test.apigee.net/"
});
const APIKEY = process.env.APIKEY;
exports.handler = async event => {
let resp;
let data;
try {
switch (event.action) {
case "RC_CREATE_GITHUB":
data = {
access_token: event.access_token,
repo_name: event.repo_name
};
resp = await axios.post(
`/repo-creation-github/?apikey=${APIKEY}`,
data
);
try {
console.log("REQ STATUS START");
console.log(resp.data.body.data.data);
console.log(resp.data.body.data.data.clone_url);
console.log(resp.data.body.data.data.owner.login);
console.log("REQ STATUS END");
resp = {
data: {
clone_url: resp.data.body.data.data.clone_url,
user: resp.data.body.data.data.owner.login
}
};
} catch (err) {
console.error(err);
}
break;
case "RU_COMMIT_GITHUB":
data = {
source_access_token: event.source_access_token,
destination_access_token: event.destination_access_token,
source_repo_url: event.source_repo_url,
destination_repo_url: event.destination_repo_url,
context:event.context
};
resp = await axios.post(`/repo-first-commit/?apikey=${APIKEY}`, data);
console.log(resp);
break;
case "RC_CREATE_CIRCLECI":
data = {
access_token: event.access_token,
project_name: event.project_name,
vcs_type: event.vcs_type,
user_name: event.user_name
};
resp = await axios.post(
`/pipeline-circle-ci-follow/?apikey=${APIKEY}`,
data
);
console.log(resp);
break;
case "RU_ENVVAR_CIRCLECI":
data = {
access_token: event.access_token,
project_name: event.project_name,
vcs_type: event.vcs_type,
user_name: event.user_name,
variables: event.variables
};
resp = await axios.post(
`/pipeline-circleci-variables/?apikey=${APIKEY}`,
data
);
console.log(resp);
break;
default:
resp = {
data: {
status: 400,
desc: "action not supported"
}
};
console.log(resp);
}
console.log(resp.data);
return resp.data;
} catch (error) {
console.log(error);
return error;
}
};