11
11
from dataclasses import dataclass , field
12
12
from typing import Dict , List , Optional , Set , cast
13
13
14
+ from openedx_webhooks import settings
14
15
from openedx_webhooks .auth import get_github_session , get_jira_session
15
16
from openedx_webhooks .bot_comments import (
16
17
BOT_COMMENT_INDICATORS ,
39
40
from openedx_webhooks .gh_projects import (
40
41
add_pull_request_to_project ,
41
42
pull_request_projects ,
43
+ pull_request_projects_info ,
42
44
update_project_pr_custom_field ,
43
45
)
44
46
from openedx_webhooks .info import (
63
65
GITHUB_MERGED_PR_OBSOLETE_LABELS ,
64
66
GITHUB_STATUS_LABELS ,
65
67
)
66
- from openedx_webhooks import settings
67
68
from openedx_webhooks .tasks import logger
68
69
from openedx_webhooks .tasks .jira_work import (
69
70
update_jira_issue ,
70
71
)
71
- from openedx_webhooks .types import GhProject , JiraId , PrDict , PrId
72
+ from openedx_webhooks .types import GhProject , JiraId , PrDict , PrGhProject , PrId
72
73
from openedx_webhooks .utils import (
73
74
get_pr_state ,
74
75
log_check_response ,
@@ -125,6 +126,9 @@ class PrCurrentInfo:
125
126
# The GitHub projects the PR is in.
126
127
github_projects : Set [GhProject ] = field (default_factory = set )
127
128
129
+ # The GitHub projects the PR is in.
130
+ github_projects_info : list [PrGhProject ] = field (default_factory = list )
131
+
128
132
# The status of the cla check.
129
133
cla_check : Optional [Dict [str , str ]] = None
130
134
@@ -190,7 +194,8 @@ def current_support_state(pr: PrDict) -> PrCurrentInfo:
190
194
current .bot_data .update (extract_data_from_comment (body ))
191
195
192
196
current .github_labels = set (lbl ["name" ] for lbl in pr ["labels" ])
193
- current .github_projects = set (pull_request_projects (pr ))
197
+ current .github_projects_info = pull_request_projects_info (pr )
198
+ current .github_projects = pull_request_projects (pr , current .github_projects_info )
194
199
current .cla_check = cla_status_on_pr (pr )
195
200
196
201
return current
@@ -402,6 +407,9 @@ def _fix_ospr(self) -> None:
402
407
# Check the GitHub projects.
403
408
self ._fix_projects ()
404
409
410
+ # Update fields in project for this PR
411
+ self ._fix_project_node_fields ()
412
+
405
413
def _fix_projects (self ) -> None :
406
414
"""
407
415
Update projects for pr.
@@ -410,19 +418,38 @@ def _fix_projects(self) -> None:
410
418
project_item_id = self .actions .add_pull_request_to_project (
411
419
pr_node_id = self .pr ["node_id" ], project = project
412
420
)
413
- if not project_item_id :
414
- continue
421
+ self .current .github_projects_info .append ({
422
+ "id" : project_item_id ,
423
+ "org" : project [0 ],
424
+ "number" : project [1 ],
425
+ })
426
+
427
+ def _fix_project_node_fields (self ) -> None :
428
+ """
429
+ Update pr fields in OSPR project board.
430
+ """
431
+ for project in self .current .github_projects_info :
432
+ if (
433
+ project ["org" ] == settings .GITHUB_OSPR_PROJECT [0 ]
434
+ and project ["number" ] == settings .GITHUB_OSPR_PROJECT [1 ]
435
+ ):
436
+ project_item_id = project ["id" ]
437
+ break
438
+ else :
439
+ return
440
+ state = get_pr_state (self .pr )
441
+ if state == "open" :
415
442
self .actions .update_project_pr_custom_field (
416
443
field_name = "Date opened" ,
417
444
field_value = self .pr ["created_at" ],
418
445
item_id = project_item_id ,
419
- project = project
446
+ project = settings . GITHUB_OSPR_PROJECT
420
447
)
421
448
# get base repo owner info
422
449
repo_spec = get_repo_spec (self .pr ["base" ]["repo" ]["full_name" ])
423
450
owner = repo_spec .owner
424
451
if not owner :
425
- continue
452
+ return
426
453
# get user info if owner is an individual
427
454
if repo_spec .is_owner_individual :
428
455
owner_info = get_github_user_info (owner )
@@ -432,7 +459,21 @@ def _fix_projects(self) -> None:
432
459
field_name = "Repo Owner / Owning Team" ,
433
460
field_value = owner ,
434
461
item_id = project_item_id ,
435
- project = project
462
+ project = settings .GITHUB_OSPR_PROJECT
463
+ )
464
+ elif state == "merged" :
465
+ self .actions .update_project_pr_custom_field (
466
+ field_name = "Date merged/closed" ,
467
+ field_value = self .pr ["merged_at" ],
468
+ item_id = project_item_id ,
469
+ project = settings .GITHUB_OSPR_PROJECT
470
+ )
471
+ elif state == "closed" :
472
+ self .actions .update_project_pr_custom_field (
473
+ field_name = "Date merged/closed" ,
474
+ field_value = self .pr ["closed_at" ],
475
+ item_id = project_item_id ,
476
+ project = settings .GITHUB_OSPR_PROJECT
436
477
)
437
478
438
479
def _make_jira_issue (self , jira_nick ) -> None :
0 commit comments