Skip to content

Commit eb345fb

Browse files
committed
feat: add configuration for enabling status comments in GitHub project
1 parent b4c7634 commit eb345fb

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

config/github-project.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@
1111
'access_token' => env('GITHUB_ACCESS_TOKEN', ''),
1212
'graphql_url' => env('GITHUB_GRAPHQL_URL', 'https://api.github.com/graphql'),
1313
],
14+
15+
'enable_status_comment' => env('GITHUB_PROJECT_ENABLE_STATUS_COMMENT', false),
1416
];

lang/en/github-project.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
'denied' => 'The event was denied.',
1111
'action_not_found' => 'Not an action event.',
1212
'missing_fields' => 'Missing required fields.',
13+
'status_comment_disabled' => 'Status comment is disabled.',
1314
],
1415
],
1516

src/Services/WebhookService.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ public function validatePayload(array $payload): ?JsonResponse
3737
if (!isset($payload['action'])) {
3838
return response()->json(
3939
['message' => __('github-project::github-project.error.event.action_not_found')],
40+
404
41+
);
42+
}
43+
44+
if (!$this->isStatusCommentEnabled($payload['changes']['field_value']['field_name'])) {
45+
return response()->json(
46+
['message' => __('github-project::github-project.error.event.status_comment_disabled')],
4047
400
4148
);
4249
}
@@ -54,6 +61,22 @@ public function validatePayload(array $payload): ?JsonResponse
5461
return null;
5562
}
5663

64+
/**
65+
* Check if the field name is "Status" and if status comments are enabled.
66+
*
67+
* @param string $fieldName
68+
*
69+
* @return bool
70+
*/
71+
public function isStatusCommentEnabled(string $fieldName): bool
72+
{
73+
if ($fieldName === 'Status' && !config('github-project.enable_status_comment')) {
74+
return false;
75+
}
76+
77+
return true;
78+
}
79+
5780
/**
5881
* @param string $contentNodeId
5982
* @param string $message

0 commit comments

Comments
 (0)