github-overlord 0.6.4__tar.gz → 0.6.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Michael Bianco
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: github-overlord
3
- Version: 0.6.4
3
+ Version: 0.6.6
4
4
  Summary: Automatically merge Dependabot PRs in public repositories
5
5
  Home-page: https://github.com/iloveitaly/github-overlord
6
6
  Keywords: github,dependabot,automation
@@ -10,7 +10,11 @@ from github.GithubObject import NotSet
10
10
  from github.Notification import Notification
11
11
  from github.PullRequest import PullRequest
12
12
 
13
- from github_overlord.stale_commenter import check_for_stale_comments, is_stale_comment
13
+ from github_overlord.stale_commenter import (
14
+ check_for_stale_comments,
15
+ inspect_repo_for_stale_prs,
16
+ is_stale_comment,
17
+ )
14
18
  from github_overlord.utils import log
15
19
 
16
20
  AUTOMATIC_MERGE_MESSAGE = "Automatically merged with GitHub overlord"
@@ -156,11 +160,14 @@ def cli():
156
160
  pass
157
161
 
158
162
 
159
- def extract_repo_reference_from_github_url(url: str):
163
+ def extract_repo_reference_from_github_url(url: str | None):
160
164
  """
161
165
  Extract the owner and repo from a GitHub URL
162
166
  """
163
167
 
168
+ if url is None:
169
+ return None
170
+
164
171
  # convert 'https://github.com/iloveitaly/todoist-digest/pulls' to 'iloveitaly/todoist-digest'
165
172
  if "github.com" in url:
166
173
  match = re.search(r"github\.com/([^/]+)/([^/]+)", url)
@@ -185,8 +192,7 @@ def dependabot(token, dry_run, repo):
185
192
  Automatically merge dependabot PRs in public repos that have passed CI checks
186
193
  """
187
194
 
188
- if repo:
189
- repo = extract_repo_reference_from_github_url(repo)
195
+ repo = extract_repo_reference_from_github_url(repo)
190
196
 
191
197
  main(token, dry_run, repo)
192
198
 
@@ -201,14 +207,25 @@ def dependabot(token, dry_run, repo):
201
207
  @click.option("--dry-run", is_flag=True, help="Run script without merging PRs")
202
208
  @click.option("--repo", help="Only process a single repository")
203
209
  def keep_alive_prs(token, dry_run, repo):
204
- repo = extract_repo_reference_from_github_url(repo)
210
+ assert token, "GitHub token is required"
211
+ # TODO should assert on openai setup
205
212
 
206
213
  github = Github(token)
207
- login = github.get_user().login
214
+ user = github.get_user()
215
+ login = user.login
216
+
217
+ repo = extract_repo_reference_from_github_url(repo)
218
+
219
+ if repo:
220
+ inspect_repo_for_stale_prs(dry_run, login, github.get_repo(repo))
221
+ return
222
+
223
+ # TODO this isn't perfect because you may be a contributor :/
224
+ user.get_repos(type="public") | fp.filter(
225
+ lambda repo: repo.owner.login != login
226
+ ) | fp.map(fp.partial(inspect_repo_for_stale_prs, dry_run, login)) | fp.to_list()
208
227
 
209
- github.get_repo(repo).get_pulls(state="open") | fp.filter(
210
- lambda pr: pr.user.login == login
211
- ) | fp.map(fp.partial(check_for_stale_comments, dry_run)) | fp.to_list()
228
+ log.info("stale PR check complete")
212
229
 
213
230
 
214
231
  def notifications(token, dry_run):
@@ -1,12 +1,26 @@
1
1
  import json
2
2
 
3
+ import funcy_pipe as fp
4
+ from github import Github
3
5
  from github.IssueComment import IssueComment
4
6
  from github.PullRequest import PullRequest
7
+ from github.Repository import Repository
5
8
  from openai import OpenAI
6
9
 
7
10
  from github_overlord.utils import log
8
11
 
9
12
 
13
+ def inspect_repo_for_stale_prs(dry_run: bool, login: str, repo: Repository):
14
+ log.debug("inspecting repo for stale PRs", repo=repo.full_name)
15
+
16
+ return (
17
+ repo.get_pulls(state="open")
18
+ | fp.filter(lambda pr: pr.user.login == login)
19
+ | fp.map(fp.partial(check_for_stale_comments, dry_run))
20
+ | fp.to_list()
21
+ )
22
+
23
+
10
24
  def check_for_stale_comments(dry_run: bool, pr: PullRequest):
11
25
  """
12
26
  Look at PRs which you have written:
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "github-overlord"
3
- version = "0.6.4"
3
+ version = "0.6.6"
4
4
  description = "Automatically merge Dependabot PRs in public repositories"
5
5
  authors = ["Michael Bianco <mike@mikebian.co>"]
6
6
  readme = "README.md"