-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocessa_evento.py
More file actions
112 lines (79 loc) · 4.89 KB
/
processa_evento.py
File metadata and controls
112 lines (79 loc) · 4.89 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
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
# -*- coding: UTF-8 -*-
from processa_dados import processaDados
import json, sys
class processaEvento:
data = ''
processaDados = None
def __init__(self, data):
self.data = data
self.processaDados = processaDados()
#Processa eventos no repositorio no Github
def processaEvento(self, evento):
dados = self.data
#Novo Pull Request
if evento == 'pull_request':
dadosPullRequest = self.processaDados.getDadosPullRequest(dados)
pull = dados['pull_request']
usuarios = {1}
head = pull['head']
if 'action' in dados and dados['action'] == 'opened' and 'id' in dadosPullRequest:
user = self.processaDados.getDadosUser(dados['pull_request']['user'])
#stats = self.processaDados.getStatsPull(pull['commits_url'])
data = pull['created_at'][0:10]
hora = pull['created_at'][11:-4]
titulo = "Novo Pull Request no repositorio "+ dados['repository']['name']
descricao = 'Aberto por <strong>'+ user['contributorNome'] +'</strong>, em <strong>'+ data +'</strong>, as \
<strong>'+ hora +'</strong>Arquivos Alterados: <strong>'+ str(pull['changed_files']) +'</strong>. \
Adiões: <strong>'+ str(pull['additions']) +'</strong>. Remoções: <strong> '\
+ str(pull['deletions']) +'</strong>',
elif 'action' in dados and dados['action'] == 'closed' and 'id' in dadosPullRequest:
user = self.processaDados.getDadosUser(pull['merged_by'])
data = pull['merged_at'][0:10]
hora = pull['merged_at'][11:-4]
merged = "Mesclado" if pull['merged'] == True else "Nao mesclado"
titulo = "Pull Request <strong>"+ pull['title'] +"</strong> no repositorio "+ dados['repository']['name'] +" fechado."
descricao = 'Fechado por <strong>'+ user['contributorNome'] +'</strong>, em <strong>'+ data +'</strong>, as \
<strong>'+ hora +'</strong>, com status de <strong>'+ merged +'</strong>.'
else:
raise Exception("Payload incompleto ou em formato incorreto.")
warnLevel = 'danger';
link = pull['html_url'];
for usuarioCod in usuarios:
self.processaDados.enviaNotificacao(usuarioCod, titulo, descricao, warnLevel, link)
return "OKZ"
# Novo Push
elif evento == 'push':
repositorio = self.processaDados.getDadosRepo(dados['repository'])
self.processaDados.getBranches(repositorio['repositorioCod'], dados['repository']['branches_url'][0:-9])
usuarios = {1}
head = dados['head_commit']
data = head['timestamp'][0:10]
hora = head['timestamp'][11:-4]
titulo = 'Novo Push no repositorio '+ repositorio['repositorioNome']
descricao = 'Ultimo commit no branch '+ dados['ref'] +',<br /> por <strong>'+ head['author']['name'] +'</strong>, \
em <strong>'+ data +'</strong>, as <strong>'+ hora +'</strong>Arquivos adicionados: <strong>'+ \
str(len(head['added'])) +'</strong>. Removidos: <strong>'+ str(len(head['removed'])) +'</strong>. \
Alterados: <strong>'+ str(len(head['modified'])) +'</strong>.';
warnLevel = 'warning';
link = head['url'];
for usuarioCod in usuarios:
self.processaDados.enviaNotificacao(usuarioCod, titulo, descricao, warnLevel, link)
return "OKX"
#Novo branch
elif evento == 'create':
if 'ref_type'in dados and dados['ref_type'] == "branch":
usuarios = {1}
user = self.processaDados.getDadosUser(dados['sender'])
repositorio = self.processaDados.getDadosRepo(dados['repository'])
self.processaDados.getBranches(repositorio['repositorioCod'], dados['repository']['branches_url'][0:-9])
data = dados['repository']['pushed_at'][0:10]
hora = dados['repository']['pushed_at'][11:-4]
titulo = 'Novo Branch criado no repositorio ' + repositorio['repositorioNome']
descricao = 'Branch ' + dados['ref'] + ' criado por <strong>' + user['contributorNome']+ '</strong>.';
warnLevel = 'warning';
link = dados['repository']['url'] +"/tree/"+ dados['ref'];
for usuarioCod in usuarios:
self.processaDados.enviaNotificacao(usuarioCod, titulo, descricao, warnLevel, link)
return "OKX"
else:
return "Evento desconhecido"