1
1
package gitlab
2
2
3
3
import (
4
+ "context"
4
5
"fmt"
5
6
"time"
6
7
8
+ "github.com/jippi/scm-engine/pkg/config"
7
9
"github.com/jippi/scm-engine/pkg/scm"
8
10
"github.com/jippi/scm-engine/pkg/stdlib"
9
11
)
@@ -51,48 +53,51 @@ func (e ContextMergeRequest) StateIsNot(anyOf ...string) bool {
51
53
}
52
54
53
55
// has_no_activity_within
54
- func (e ContextMergeRequest ) HasNoActivityWithin (input any ) bool {
55
- return ! e .HasAnyActivityWithin (input )
56
+ func (e ContextMergeRequest ) HasNoActivityWithin (ctx context. Context , input any ) bool {
57
+ return ! e .HasAnyActivityWithin (ctx , input )
56
58
}
57
59
58
60
// has_any_activity_within
59
- func (e ContextMergeRequest ) HasAnyActivityWithin (input any ) bool {
61
+ func (e ContextMergeRequest ) HasAnyActivityWithin (ctx context. Context , input any ) bool {
60
62
dur := stdlib .ToDuration (input )
61
63
now := time .Now ()
64
+ cfg := config .FromContext (ctx )
62
65
63
66
for _ , note := range e .Notes {
64
- if now .Sub (note .UpdatedAt ) < dur {
65
- return true
67
+ // Check if we should ignore the actor (user) activity
68
+ if cfg .IgnoreActivityFrom .Matches (note .Author .ToActorMatcher ()) {
69
+ continue
66
70
}
67
- }
68
71
69
- if e . LastCommit != nil {
70
- if now .Sub (* e . LastCommit . CommittedDate ) < dur {
72
+ // Check is within the configured duration
73
+ if now .Sub (note . UpdatedAt ) < dur {
71
74
return true
72
75
}
73
76
}
74
77
75
- return false
78
+ // If we have a recent commit, check if its within the duration
79
+ return e .LastCommit != nil && now .Sub (* e .LastCommit .CommittedDate ) < dur
76
80
}
77
81
78
82
// has_no_user_activity_within
79
- func (e ContextMergeRequest ) HasNoUserActivityWithin (input any ) bool {
80
- return ! e .HasUserActivityWithin (input )
83
+ func (e ContextMergeRequest ) HasNoUserActivityWithin (ctx context. Context , input any ) bool {
84
+ return ! e .HasUserActivityWithin (ctx , input )
81
85
}
82
86
83
87
// has_user_activity_within
84
- func (e ContextMergeRequest ) HasUserActivityWithin (input any ) bool {
88
+ func (e ContextMergeRequest ) HasUserActivityWithin (ctx context. Context , input any ) bool {
85
89
dur := stdlib .ToDuration (input )
86
90
now := time .Now ()
91
+ cfg := config .FromContext (ctx )
87
92
88
93
for _ , note := range e .Notes {
89
- // Ignore "my" activity
90
- if e . CurrentUser . Username == note .Author .Username {
94
+ // Check if we should ignore the actor (user) activity
95
+ if cfg . IgnoreActivityFrom . Matches ( note .Author .ToActorMatcher ()) {
91
96
continue
92
97
}
93
98
94
- // Ignore bots
95
- if e .Author .Bot {
99
+ // Ignore "scm-engine" activity since we shouldn't consider ourself a user
100
+ if e .CurrentUser . Username == note . Author .Username {
96
101
continue
97
102
}
98
103
@@ -101,13 +106,8 @@ func (e ContextMergeRequest) HasUserActivityWithin(input any) bool {
101
106
}
102
107
}
103
108
104
- if e .LastCommit != nil {
105
- if now .Sub (* e .LastCommit .CommittedDate ) < dur {
106
- return true
107
- }
108
- }
109
-
110
- return false
109
+ // If we have a recent commit, check if its within the duration
110
+ return e .LastCommit != nil && now .Sub (* e .LastCommit .CommittedDate ) < dur
111
111
}
112
112
113
113
func (e ContextMergeRequest ) ModifiedFilesList (patterns ... string ) []string {
0 commit comments