@@ -108,18 +108,52 @@ def packit(self) -> PackitAPI:
108108 )
109109 return self ._packit
110110
111+ def handle_existing_dist_git_pr (self ) -> bool :
112+ """Sync changes in source-git PR to already existing dist-git PR.
113+
114+ Returns:
115+ was the sync successful
116+ """
117+ logger .info (
118+ f"{ self .source_git_pr_model } already has corresponding { self .dist_git_pr_model } "
119+ )
120+ if self .dist_git_pr :
121+ msg = ""
122+ if self .action == GitlabEventAction .closed .value :
123+ msg = f"[Source-git MR]({ self .mr_url } ) has been closed."
124+ self .dist_git_pr .close ()
125+ elif self .action == GitlabEventAction .reopen .value :
126+ msg = f"[Source-git MR]({ self .mr_url } ) has been reopened."
127+ # https://github.com/packit/ogr/pull/714
128+ # self.dist_git_pr.reopen()
129+ elif self .action == GitlabEventAction .update .value :
130+ msg = f"[Source-git MR]({ self .mr_url } ) has been updated."
131+ # TODO: update the dist-git PR?
132+ elif self .action == GitlabEventAction .opened .value :
133+ # Are you trying to re-send a webhook payload to the endpoint manually?
134+ # If so and you expect a new dist-git PR being opened, you first
135+ # have to remove the old relation from db.
136+ logger .error (f"[Source-git MR]({ self .mr_url } ) opened. (again???)" )
137+ return False
138+ logger .info (msg )
139+ self .dist_git_pr .comment (msg )
140+ return True
141+
111142 def run (self ) -> TaskResults :
112143 """
113144 If user creates a merge-request on the source-git repository,
114145 create a matching merge-request to the dist-git repository.
115146 """
116147 if not self .handle_target ():
117148 logger .debug (
118- "Not creating a dist-git MR from "
149+ "Not creating/updating a dist-git MR from "
119150 f"{ self .target_repo } :{ self .target_repo_branch } "
120151 )
121152 return TaskResults (success = True )
122153
154+ if self .dist_git_pr_model :
155+ return TaskResults (success = self .handle_existing_dist_git_pr ())
156+
123157 if not self .package_config :
124158 logger .debug ("No package config found." )
125159 return TaskResults (success = True )
@@ -137,25 +171,6 @@ def run(self) -> TaskResults:
137171 logger .info (msg )
138172 return TaskResults (success = True )
139173
140- if self .dist_git_pr_model :
141- logger .info (
142- f"{ self .source_git_pr_model } already has corresponding { self .dist_git_pr_model } "
143- )
144- if self .dist_git_pr :
145- if self .action == GitlabEventAction .closed .value :
146- msg = f"[Source-git MR]({ self .mr_url } ) has been closed."
147- self .dist_git_pr .close ()
148- elif self .action == GitlabEventAction .reopen .value :
149- msg = f"[Source-git MR]({ self .mr_url } ) has been reopened."
150- # https://github.com/packit/ogr/pull/714
151- # self.dist_git_pr.reopen()
152- else :
153- logger .error (f"Unknown action { self .action } " )
154- return TaskResults (success = False )
155- logger .info (msg )
156- self .dist_git_pr .comment (msg )
157- return TaskResults (success = True )
158-
159174 dg_mr_info = f"""###### Info for package maintainer
160175This MR has been automatically created from
161176[this source-git MR]({ self .mr_url } )."""
0 commit comments