-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
47 lines (40 loc) · 1.53 KB
/
main.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
$(document).ready(function(){
createIssue()
});
function createIssue(){
const OWNER = "pokemongovet/";
const REPOSITORY = "pokemongovet-bot";
$('#submit-issue').on('click',function(){
var username = $('#user').val(); /*username GIT AQUI */
var password = $('#password').val(); /* password GIT AQUI */
var title = $("#title-issue").val();
var body = $("#comentario-issue").val();
$.ajax({
headers: {
"Authorization": "Basic " + btoa(username + ":" + password),
"Content-Type":"application/json"
},
type:"POST",
url: "https://api.github.com/repos/"+OWNER+REPOSITORY+"/issues",
data:JSON.stringify({title: title,body: body}),
success:(data)=>{
alert('Issue criada com sucesso');
},error:(error)=>{
console.dir(error)
switch (error.responseJSON.message) {
case "Validation Failed":
alert("O Título e Comentário são obrigatórios!");
break;
case "Bad credentials":
alert("Você não tem permissão para criar issue!");
break;
case "Not Found":
alert('É necessário que você se autentique!')
break;
default:
break;
}
}
});
});
}