@@ -25,7 +25,7 @@ type bot struct {
2525	defaultNamespace  string 
2626	configurations    map [string ]Configuration 
2727
28- 	cacheLocker        * sync.Mutex 
28+ 	globalLocker      * sync.Mutex 
2929	namespaceMutexes  * cache.Cache 
3030	repoIssueMutexes  * cache.Cache 
3131}
@@ -42,24 +42,32 @@ func (b *bot) getCurrentConfiguration(namespace string) (Configuration, error) {
4242	return  configuration , nil 
4343}
4444
45- func  (b  * bot ) processRules (configuration  Configuration , data  EventData ) * HandledEventResult  {
46- 	id  :=  fmt .Sprintf ("%s/%s#%d" , data .GetOwner (), data .GetRepo (), data .GetNumber ())
47- 	util .Logger .Debug ("acquire global lock during rules process" )
48- 	b .cacheLocker .Lock ()
49- 	locker , exists  :=  b .repoIssueMutexes .Get (id )
45+ func  (b  * bot ) processRules (
46+ 	namespaceLock  * sync.Mutex ,
47+ 	configuration  Configuration ,
48+ 	partial  EventData ,
49+ 	r  * http.Request ) * HandledEventResult  {
50+ 	id  :=  fmt .Sprintf ("%s/%s#%d" , partial .GetOwner (), partial .GetRepo (), partial .GetNumber ())
51+ 	util .Logger .Debug ("acquire namespace lock during rules process" )
52+ 	issueLocker , exists  :=  b .repoIssueMutexes .Get (id )
5053	if  ! exists  {
51- 		locker  =  & sync.Mutex {}
52- 		b .repoIssueMutexes .Set (id , locker , cache .DefaultExpiration )
54+ 		issueLocker  =  & sync.Mutex {}
55+ 		b .repoIssueMutexes .Set (id , issueLocker , cache .DefaultExpiration )
5356	}
5457	util .Logger .Debug ("acquire repo issue %s lock during rules process" , id )
55- 	locker .(* sync.Mutex ).Lock ()
56- 	defer  locker .(* sync.Mutex ).Unlock ()
57- 	util .Logger .Debug ("release global  lock during rules process" )
58- 	b . cacheLocker .Unlock ()
58+ 	issueLocker .(* sync.Mutex ).Lock ()
59+ 	defer  issueLocker .(* sync.Mutex ).Unlock ()
60+ 	util .Logger .Debug ("release namespace  lock during rules process" )
61+ 	namespaceLock .Unlock ()
5962	applied  :=  make ([]Rule , 0 )
6063	result  :=  & HandledEventResult {
6164		AppliedRules : []string {},
6265	}
66+ 	data , ok  :=  completeBuildFromRequest (configuration .GetClientConfig (), r )
67+ 	if  ! ok  {
68+ 		util .Logger .Debug ("Skipping rule processing for %s (couldn't build complete data)" , id )
69+ 		return  result 
70+ 	}
6371	for  _ , rule  :=  range  configuration .GetRules () {
6472		if  rule .Accept (data ) {
6573			util .Logger .Debug ("Accepting rule %s for '%s'" , rule .Name (), data .GetTitle ())
@@ -78,7 +86,7 @@ func (b *bot) processRules(configuration Configuration, data EventData) *Handled
7886
7987func  (b  * bot ) HandleEvent (r  * http.Request ) * HandledEventResult  {
8088	namespace  :=  r .URL .Query ().Get ("namespace" )
81- 	b .cacheLocker .Lock ()
89+ 	b .globalLocker .Lock ()
8290	util .Logger .Debug ("acquire global lock during namespace process" )
8391	locker , exists  :=  b .namespaceMutexes .Get (namespace )
8492	if  ! exists  {
@@ -88,7 +96,7 @@ func (b *bot) HandleEvent(r *http.Request) *HandledEventResult {
8896	util .Logger .Debug ("acquire namespace %s lock" , namespace )
8997	locker .(* sync.Mutex ).Lock ()
9098	util .Logger .Debug ("release global lock during namespace process" )
91- 	b .cacheLocker .Unlock ()
99+ 	b .globalLocker .Unlock ()
92100	workingConfiguration , err  :=  b .getCurrentConfiguration (namespace )
93101	if  err  !=  nil  {
94102		locker .(* sync.Mutex ).Unlock ()
@@ -100,14 +108,13 @@ func (b *bot) HandleEvent(r *http.Request) *HandledEventResult {
100108		return  & HandledEventResult {Message : "Skipping rules processing (could be not supported event type)" }
101109	}
102110	util .Logger .Debug ("release namespace %s lock" , namespace )
103- 	locker .(* sync.Mutex ).Unlock ()
104- 	return  b .processRules (workingConfiguration , data )
111+ 	return  b .processRules (locker .(* sync.Mutex ), workingConfiguration , data , r )
105112}
106113
107114func  New (configPaths  ... string ) (Bot , error ) {
108115	b  :=  & bot {
109116		configurations :   make (map [string ]Configuration ),
110- 		cacheLocker :       & sync.Mutex {},
117+ 		globalLocker :      & sync.Mutex {},
111118		namespaceMutexes : cache .New (time .Minute , 30 * time .Second ),
112119		repoIssueMutexes : cache .New (time .Minute , 20 * time .Second ),
113120	}
0 commit comments