@@ -10,27 +10,26 @@ def get_github_event(github_event_path):
10
10
with open (github_event_path ) as f :
11
11
github_event = json .load (f )
12
12
if os .environ .get ('DEBUG_EVENT' ) is not None :
13
+ print (os .environ ['GITHUB_EVENT_NAME' ])
13
14
print (json .dumps (github_event , sort_keys = True , indent = 2 ))
14
15
return github_event
15
16
16
17
17
- def ignore_event (github_event ):
18
- if 'schedule' in github_event :
19
- print ("Allow schedule event." )
20
- return False
21
- # Ignore push events on deleted branches
22
- # The event we want to ignore occurs when a PR is created but the repository owner decides
23
- # not to commit the changes. They close the PR and delete the branch. This creates a
24
- # "push" event that we want to ignore, otherwise it will create another branch and PR on
25
- # the same commit.
26
- deleted = "{deleted}" .format (** github_event )
27
- if deleted == "True" :
28
- print ("Ignoring delete branch event." )
29
- return True
30
- ref = "{ref}" .format (** github_event )
31
- if not ref .startswith ('refs/heads/' ):
32
- print ("Ignoring events for tags and remotes." )
33
- return True
18
+ def ignore_event (event_name , event_data ):
19
+ if event_name == "push" :
20
+ # Ignore push events on deleted branches
21
+ # The event we want to ignore occurs when a PR is created but the repository owner decides
22
+ # not to commit the changes. They close the PR and delete the branch. This creates a
23
+ # "push" event that we want to ignore, otherwise it will create another branch and PR on
24
+ # the same commit.
25
+ deleted = "{deleted}" .format (** event_data )
26
+ if deleted == "True" :
27
+ print ("Ignoring delete branch event." )
28
+ return True
29
+ ref = "{ref}" .format (** event_data )
30
+ if not ref .startswith ('refs/heads/' ):
31
+ print ("Ignoring events for tags and remotes." )
32
+ return True
34
33
return False
35
34
36
35
@@ -41,13 +40,13 @@ def pr_branch_exists(repo, branch):
41
40
return False
42
41
43
42
44
- def get_head_author (github_event ):
45
- if 'schedule' in github_event :
43
+ def get_head_author (event_name , event_data ):
44
+ if event_name == "push" :
45
+ email = "{head_commit[author][email]}" .format (** event_data )
46
+ name = "{head_commit[author][name]}" .format (** event_data )
47
+ else :
46
48
email = os .environ ['GITHUB_ACTOR' ] + '@users.noreply.github.com'
47
49
name = os .environ ['GITHUB_ACTOR' ]
48
- else :
49
- email = "{head_commit[author][email]}" .format (** github_event )
50
- name = "{head_commit[author][name]}" .format (** github_event )
51
50
return email , name
52
51
53
52
@@ -79,7 +78,7 @@ def create_pull_request(token, repo, head, base, title, body):
79
78
head = head )
80
79
81
80
82
- def process_event (github_event , repo , branch , base ):
81
+ def process_event (event_name , event_data , repo , branch , base ):
83
82
# Fetch required environment variables
84
83
github_token = os .environ ['GITHUB_TOKEN' ]
85
84
github_repository = os .environ ['GITHUB_REPOSITORY' ]
@@ -96,7 +95,7 @@ def process_event(github_event, repo, branch, base):
96
95
"[create-pull-request](https://github.com/peter-evans/create-pull-request) GitHub Action" )
97
96
98
97
# Get the HEAD committer's email and name
99
- author_email , author_name = get_head_author (github_event )
98
+ author_email , author_name = get_head_author (event_name , event_data )
100
99
# Set git configuration
101
100
set_git_config (repo .git , author_email , author_name )
102
101
# Update URL for the 'origin' remote
@@ -121,9 +120,10 @@ def process_event(github_event, repo, branch, base):
121
120
122
121
123
122
# Get the JSON event data
124
- github_event = get_github_event (os .environ ['GITHUB_EVENT_PATH' ])
123
+ event_name = os .environ ['GITHUB_EVENT_NAME' ]
124
+ event_data = get_github_event (os .environ ['GITHUB_EVENT_PATH' ])
125
125
# Check if this event should be ignored
126
- if not ignore_event (github_event ):
126
+ if not ignore_event (event_name , event_data ):
127
127
# Set the repo to the working directory
128
128
repo = Repo (os .getcwd ())
129
129
@@ -142,7 +142,7 @@ def process_event(github_event, repo, branch, base):
142
142
# Check if there are changes to pull request
143
143
if repo .is_dirty () or len (repo .untracked_files ) > 0 :
144
144
print ("Repository has modified or untracked files." )
145
- process_event (github_event , repo , branch , base )
145
+ process_event (event_name , event_data , repo , branch , base )
146
146
else :
147
147
print ("Repository has no modified or untracked files. Skipping." )
148
148
else :
0 commit comments