saltext.github 1.1.0__py3-none-any.whl

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.
Files changed (73) hide show
  1. saltext/github/__init__.py +31 -0
  2. saltext/github/modules/__init__.py +0 -0
  3. saltext/github/modules/github.py +1873 -0
  4. saltext/github/modules/github_org.py +667 -0
  5. saltext/github/modules/github_repo.py +1658 -0
  6. saltext/github/modules/github_user.py +75 -0
  7. saltext/github/resources/__init__.py +0 -0
  8. saltext/github/resources/github/__init__.py +251 -0
  9. saltext/github/resources/github/modules/__init__.py +0 -0
  10. saltext/github/resources/github/modules/actions.py +175 -0
  11. saltext/github/resources/github/modules/config.py +69 -0
  12. saltext/github/resources/github/modules/deploy_key.py +122 -0
  13. saltext/github/resources/github/modules/environment.py +241 -0
  14. saltext/github/resources/github/modules/grains.py +18 -0
  15. saltext/github/resources/github/modules/issue.py +157 -0
  16. saltext/github/resources/github/modules/label.py +161 -0
  17. saltext/github/resources/github/modules/milestone.py +103 -0
  18. saltext/github/resources/github/modules/pages.py +149 -0
  19. saltext/github/resources/github/modules/pull.py +90 -0
  20. saltext/github/resources/github/modules/repo.py +155 -0
  21. saltext/github/resources/github/modules/ruleset.py +144 -0
  22. saltext/github/resources/github/modules/saltutil.py +24 -0
  23. saltext/github/resources/github/modules/state.py +116 -0
  24. saltext/github/resources/github/modules/test.py +29 -0
  25. saltext/github/resources/github/states/__init__.py +0 -0
  26. saltext/github/resources/github/states/actions.py +117 -0
  27. saltext/github/resources/github/states/deploy_key.py +130 -0
  28. saltext/github/resources/github/states/environment.py +99 -0
  29. saltext/github/resources/github/states/label.py +71 -0
  30. saltext/github/resources/github/states/pages.py +92 -0
  31. saltext/github/resources/github/states/repo.py +108 -0
  32. saltext/github/resources/github/states/ruleset.py +81 -0
  33. saltext/github/states/__init__.py +0 -0
  34. saltext/github/states/github.py +966 -0
  35. saltext/github/states/github_org.py +369 -0
  36. saltext/github/states/github_repo.py +722 -0
  37. saltext/github/utils/__init__.py +72 -0
  38. saltext/github/utils/gh/__init__.py +14 -0
  39. saltext/github/utils/gh/actions.py +195 -0
  40. saltext/github/utils/gh/cache.py +126 -0
  41. saltext/github/utils/gh/client.py +534 -0
  42. saltext/github/utils/gh/deploy_keys.py +121 -0
  43. saltext/github/utils/gh/environments.py +271 -0
  44. saltext/github/utils/gh/exceptions.py +28 -0
  45. saltext/github/utils/gh/grains_files.py +366 -0
  46. saltext/github/utils/gh/issues.py +193 -0
  47. saltext/github/utils/gh/labels.py +142 -0
  48. saltext/github/utils/gh/members.py +157 -0
  49. saltext/github/utils/gh/milestones.py +122 -0
  50. saltext/github/utils/gh/pages.py +128 -0
  51. saltext/github/utils/gh/profile.py +458 -0
  52. saltext/github/utils/gh/pulls.py +99 -0
  53. saltext/github/utils/gh/repos.py +465 -0
  54. saltext/github/utils/gh/resource.py +35 -0
  55. saltext/github/utils/gh/rulesets.py +191 -0
  56. saltext/github/utils/gh/statecores/__init__.py +70 -0
  57. saltext/github/utils/gh/statecores/actions.py +180 -0
  58. saltext/github/utils/gh/statecores/deploy_keys.py +241 -0
  59. saltext/github/utils/gh/statecores/environments.py +212 -0
  60. saltext/github/utils/gh/statecores/labels.py +116 -0
  61. saltext/github/utils/gh/statecores/pages.py +177 -0
  62. saltext/github/utils/gh/statecores/repo.py +249 -0
  63. saltext/github/utils/gh/statecores/rulesets.py +115 -0
  64. saltext/github/utils/gh/teams.py +375 -0
  65. saltext/github/utils/gh/users.py +87 -0
  66. saltext/github/version.py +1 -0
  67. saltext_github-1.1.0.dist-info/METADATA +151 -0
  68. saltext_github-1.1.0.dist-info/RECORD +73 -0
  69. saltext_github-1.1.0.dist-info/WHEEL +5 -0
  70. saltext_github-1.1.0.dist-info/entry_points.txt +2 -0
  71. saltext_github-1.1.0.dist-info/licenses/LICENSE +201 -0
  72. saltext_github-1.1.0.dist-info/licenses/NOTICE +10 -0
  73. saltext_github-1.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,1873 @@
1
+ """
2
+ General module for interacting with the GitHub v3 API.
3
+
4
+ Contains functionality that is not tied to a single organization or
5
+ repository, e.g. generic account lookups, the token's API rate limit
6
+ status or direct queries against arbitrary API endpoints.
7
+
8
+ :depends: PyGithub python module
9
+
10
+ .. important::
11
+
12
+ All organization- and repository-related functions in this module are
13
+ deprecated in favor of the :py:mod:`github_org
14
+ <saltext.github.modules.github_org>` and :py:mod:`github_repo
15
+ <saltext.github.modules.github_repo>` modules, which raise errors
16
+ instead of logging and returning ``False``. The non-deprecated
17
+ functions in this module behave like the scoped modules in this
18
+ regard.
19
+
20
+ Configuration
21
+ -------------
22
+
23
+ This module reads its configuration from profiles, which are described
24
+ in the :ref:`configuration guide <github-configuration>`. All functions
25
+ accept a ``profile`` argument, defaulting to the ``github`` profile.
26
+ """
27
+
28
+ import logging
29
+
30
+ from salt.exceptions import CommandExecutionError
31
+
32
+ from saltext.github.utils import filter_unset
33
+
34
+ try:
35
+ from saltext.github.utils.gh import client as gh_client
36
+ from saltext.github.utils.gh import issues as gh_issues
37
+ from saltext.github.utils.gh import members as gh_members
38
+ from saltext.github.utils.gh import milestones as gh_milestones
39
+ from saltext.github.utils.gh import profile as gh_profile
40
+ from saltext.github.utils.gh import pulls as gh_pulls
41
+ from saltext.github.utils.gh import repos as gh_repos
42
+ from saltext.github.utils.gh import rulesets as gh_rulesets
43
+ from saltext.github.utils.gh import teams as gh_teams
44
+ from saltext.github.utils.gh import users as gh_users
45
+ from saltext.github.utils.gh.exceptions import GitHubApiError
46
+ from saltext.github.utils.gh.exceptions import GitHubNotFoundError
47
+
48
+ HAS_LIBS = True
49
+ except ImportError: # pragma: no cover
50
+ HAS_LIBS = False
51
+
52
+ log = logging.getLogger(__name__)
53
+
54
+ __virtualname__ = "github"
55
+
56
+
57
+ def __virtual__():
58
+ if HAS_LIBS:
59
+ return __virtualname__
60
+ return ( # pragma: no cover
61
+ False,
62
+ "The github execution module cannot be loaded: PyGithub library is not installed.",
63
+ )
64
+
65
+
66
+ def _get_conn(profile):
67
+ """
68
+ Return the GitHub connection, cached into __context__ for performance
69
+ """
70
+ return gh_profile.get_conn(profile, opts=__opts__, context=__context__)
71
+
72
+
73
+ def _get_conn_repo(profile, repo_name) -> tuple[object, str]:
74
+ return _get_conn(profile), repo_name or _get_config_value(profile, "repo_name")
75
+
76
+
77
+ def _get_config_value(profile, config_name):
78
+ """
79
+ Helper function that returns a profile's configuration value based on
80
+ the supplied configuration name.
81
+
82
+ profile
83
+ The profile name that contains configuration information.
84
+
85
+ config_name
86
+ The configuration item's name to use to return configuration values.
87
+ """
88
+ return gh_profile.get_config_value(profile, config_name, opts=__opts__, context=__context__)
89
+
90
+
91
+ def _get_owner(profile):
92
+ """
93
+ Helper function that returns a profile's default repository owner
94
+ (``owner``, legacy alias ``org_name``), or None when unset.
95
+ """
96
+ return gh_profile.get_owner(profile, opts=__opts__, context=__context__)
97
+
98
+
99
+ def query(
100
+ path, params=None, method="GET", headers=None, data=None, per_page=None, profile="github"
101
+ ):
102
+ """
103
+ Make a direct call to the GitHub API, transparently following
104
+ pagination. Useful for endpoints without a dedicated wrapper function.
105
+
106
+ .. versionadded:: 1.1.0
107
+
108
+ CLI Example:
109
+
110
+ .. code-block:: bash
111
+
112
+ salt-call github.query repos/saltstack/salt
113
+ salt-call github.query orgs/my-org/members per_page=100
114
+ salt-call github.query repos/my-org/my-repo/labels method=POST data='{name: bug}'
115
+
116
+ path
117
+ URL path to query, either as a string or a list of segments.
118
+
119
+ params
120
+ Mapping of query parameters.
121
+
122
+ method
123
+ HTTP method to use. Defaults to ``GET``.
124
+
125
+ headers
126
+ Mapping of extra headers to send.
127
+
128
+ data
129
+ Request body, either as a mapping or a JSON string.
130
+
131
+ per_page
132
+ Pagination size, maximum 100.
133
+
134
+ profile
135
+ Profile configuration name to use. Defaults to ``github``.
136
+
137
+ Returns the decoded response data. List results are merged across pages.
138
+ Raises :py:class:`CommandExecutionError <salt.exceptions.CommandExecutionError>`
139
+ subclasses on error responses.
140
+ """
141
+ if isinstance(path, str):
142
+ path = path.strip("/")
143
+ return _get_conn(profile).query(
144
+ path, params=params, method=method, headers=headers, data=data, per_page=per_page
145
+ )
146
+
147
+
148
+ def rate_limit(profile="github"):
149
+ """
150
+ Return the API rate limit status of the profile's token, keyed by
151
+ resource (``core``, ``search``, ...).
152
+
153
+ .. versionadded:: 1.1.0
154
+
155
+ CLI Example:
156
+
157
+ .. code-block:: bash
158
+
159
+ salt-call github.rate_limit
160
+
161
+ profile
162
+ Profile configuration name to use. Defaults to ``github``.
163
+ """
164
+ return gh_client.rate_limit(_get_conn(profile))
165
+
166
+
167
+ def revoke_app_token(profile="github"):
168
+ """
169
+ Revoke the GitHub App installation access token the profile
170
+ currently authenticates with and drop the associated cached
171
+ connections, ensuring a subsequent call mints a fresh token.
172
+ Only valid for GitHub App (:ghconf:`app_id`) profiles.
173
+
174
+ Minted tokens are valid for one hour (fixed by GitHub) and are
175
+ never persisted by this extension, so revocation is optional
176
+ hygiene – useful e.g. as the last step of an ephemeral CI run.
177
+
178
+ .. versionadded:: 1.1.0
179
+
180
+ CLI Example:
181
+
182
+ .. code-block:: bash
183
+
184
+ salt-call github.revoke_app_token
185
+
186
+ profile
187
+ Profile configuration name to use. Defaults to ``github``.
188
+ """
189
+ conn = _get_conn(profile)
190
+ gh_client.revoke_installation_token(conn)
191
+ # The revoked token stays attached to the connection's auth
192
+ # (PyGithub only re-mints on expiry, not on auth failures) -
193
+ # evict all context entries sharing it so later invocations
194
+ # build a fresh connection.
195
+ for key in list(__context__):
196
+ if key == f"github.conn.{conn.ident}" or (
197
+ key.startswith("github.profile.")
198
+ and getattr(__context__[key], "ident", None) == conn.ident
199
+ ):
200
+ __context__.pop(key)
201
+ return True
202
+
203
+
204
+ def account_info(name=None, profile="github"):
205
+ """
206
+ Return the public profile of any user or organization account
207
+ (distinguished via the returned ``type`` field).
208
+
209
+ The scoped variants of this function — :py:func:`github_user.info
210
+ <saltext.github.modules.github_user.info>` and :py:func:`github_org.info
211
+ <saltext.github.modules.github_org.info>` — **fail** when the account
212
+ is not of the corresponding type.
213
+
214
+ .. versionadded:: 1.1.0
215
+
216
+ CLI Example:
217
+
218
+ .. code-block:: bash
219
+
220
+ salt-call github.account_info github-handle
221
+ salt-call github.account_info # the profile's owner
222
+
223
+ name
224
+ Login of the account to look up. Defaults to the profile's
225
+ :ghconf:`owner` (which itself defaults to the token's user).
226
+
227
+ profile
228
+ Profile configuration name to use. Defaults to ``github``.
229
+ """
230
+ return gh_users.get_info(_get_conn(profile), name)
231
+
232
+
233
+ ###########################################################################################
234
+ # Anything below here is deprecated. Replacement functions are in github_org/github_repo. #
235
+ ###########################################################################################
236
+
237
+
238
+ def get_user(name, profile="github", user_details=False):
239
+ """
240
+ Get a GitHub user by name.
241
+
242
+ .. deprecated:: 1.1.0
243
+ Despite its name, this function looks up the user's membership in
244
+ the profile's organization, not a generic user account. Use
245
+ :py:func:`github_org.get_member <saltext.github.modules.github_org.get_member>`
246
+ for the same functionality, or :py:func:`github.account_info
247
+ <saltext.github.modules.github.account_info>` for looking up arbitrary
248
+ accounts.
249
+
250
+ name
251
+ The user for which to obtain information.
252
+
253
+ profile
254
+ The name of the profile configuration to use. Defaults to ``github``.
255
+
256
+ user_details
257
+ Prints user information details. Defaults to ``False``. If the user is
258
+ already in the organization and user_details is set to False, the
259
+ get_user function returns ``True``. If the user is not already present
260
+ in the organization, user details will be printed by default.
261
+
262
+ CLI Example:
263
+
264
+ .. code-block:: bash
265
+
266
+ salt myminion github.get_user github-handle
267
+ salt myminion github.get_user github-handle user_details=true
268
+ """
269
+
270
+ if not user_details and name in list_users(profile):
271
+ # User is in the org, no need for additional Data
272
+ return True
273
+
274
+ try:
275
+ return gh_members.get_info(_get_conn(profile), name)
276
+ except GitHubNotFoundError:
277
+ log.error("Resource not found", exc_info_on_loglevel=logging.DEBUG)
278
+ return False
279
+
280
+
281
+ def list_users(profile="github", ignore_cache=False):
282
+ """
283
+ List all users within the organization.
284
+
285
+ .. deprecated:: 1.1.0
286
+ Use :py:func:`github_org.list_members <saltext.github.modules.github_org.list_members>` instead.
287
+
288
+ profile
289
+ The name of the profile configuration to use. Defaults to ``github``.
290
+
291
+ ignore_cache
292
+ Bypasses the use of cached users.
293
+
294
+ CLI Example:
295
+
296
+ .. code-block:: bash
297
+
298
+ salt myminion github.list_users
299
+ salt myminion github.list_users profile='my-github-profile'
300
+ """
301
+ return gh_members.list_all(_get_conn(profile), ignore_cache=ignore_cache)
302
+
303
+
304
+ def add_user(name, profile="github"):
305
+ """
306
+ Add a GitHub user.
307
+
308
+ .. deprecated:: 1.1.0
309
+ Use :py:func:`github_org.add_member <saltext.github.modules.github_org.add_member>` instead.
310
+
311
+ name
312
+ The user for which to obtain information.
313
+
314
+ profile
315
+ The name of the profile configuration to use. Defaults to ``github``.
316
+
317
+ CLI Example:
318
+
319
+ .. code-block:: bash
320
+
321
+ salt myminion github.add_user github-handle
322
+ """
323
+
324
+ try:
325
+ return gh_members.invite(_get_conn(profile), name)
326
+ except GitHubNotFoundError:
327
+ log.error("Resource not found", exc_info_on_loglevel=logging.DEBUG)
328
+ return False
329
+
330
+
331
+ def remove_user(name, profile="github"):
332
+ """
333
+ Remove a Github user by name.
334
+
335
+ .. deprecated:: 1.1.0
336
+ Use :py:func:`github_org.remove_member <saltext.github.modules.github_org.remove_member>` instead.
337
+
338
+ name
339
+ The user for which to obtain information.
340
+
341
+ profile
342
+ The name of the profile configuration to use. Defaults to ``github``.
343
+
344
+ CLI Example:
345
+
346
+ .. code-block:: bash
347
+
348
+ salt myminion github.remove_user github-handle
349
+ """
350
+
351
+ try:
352
+ return gh_members.remove(_get_conn(profile), name)
353
+ except GitHubNotFoundError:
354
+ log.error("Resource not found", exc_info_on_loglevel=logging.DEBUG)
355
+ return False
356
+
357
+
358
+ def get_issue(issue_number, repo_name=None, profile="github", output="min"):
359
+ """
360
+ Return information about a single issue in a named repository.
361
+
362
+ .. deprecated:: 1.1.0
363
+ Use :py:func:`github_repo.get_issue <saltext.github.modules.github_repo.get_issue>` instead.
364
+
365
+ issue_number
366
+ The number of the issue to retrieve.
367
+
368
+ repo_name
369
+ The name of the repository from which to get the issue. This argument is
370
+ required, either passed via the CLI, or defined in the configured
371
+ profile. A ``repo_name`` passed as a CLI argument will override the
372
+ :ghconf:`repo_name` defined in the configured profile, if provided.
373
+
374
+ profile
375
+ The name of the profile configuration to use. Defaults to ``github``.
376
+
377
+ output
378
+ The amount of data returned by each issue. Defaults to ``min``. Change
379
+ to ``full`` to see all issue output.
380
+
381
+ CLI Example:
382
+
383
+ .. code-block:: bash
384
+
385
+ salt myminion github.get_issue 514
386
+ salt myminion github.get_issue 514 repo_name=salt
387
+ """
388
+ ret = {}
389
+ try:
390
+ issue_data = gh_issues.get(*_get_conn_repo(profile, repo_name), issue_number)
391
+ except GitHubApiError:
392
+ return ret
393
+
394
+ issue_id = (issue_data or {}).get("id")
395
+
396
+ if issue_id:
397
+ if output.lower() == "full":
398
+ ret[issue_id] = issue_data
399
+ else:
400
+ ret[issue_id] = gh_issues.format_issue(issue_data)
401
+
402
+ return ret
403
+
404
+
405
+ def get_issue_comments(issue_number, repo_name=None, profile="github", since=None, output="min"):
406
+ """
407
+ Return information about the comments for a given issue in a named repository.
408
+
409
+ .. deprecated:: 1.1.0
410
+ Use :py:func:`github_repo.get_issue_comments <saltext.github.modules.github_repo.get_issue_comments>` instead.
411
+
412
+ issue_number
413
+ The number of the issue for which to retrieve comments.
414
+
415
+ repo_name
416
+ The name of the repository to which the issue belongs. This argument is
417
+ required, either passed via the CLI, or defined in the configured
418
+ profile. A ``repo_name`` passed as a CLI argument will override the
419
+ :ghconf:`repo_name` defined in the configured profile, if provided.
420
+
421
+ profile
422
+ The name of the profile configuration to use. Defaults to ``github``.
423
+
424
+ since
425
+ Only comments updated at or after this time are returned. This is a
426
+ timestamp in ISO 8601 format: ``YYYY-MM-DDTHH:MM:SSZ``.
427
+
428
+ output
429
+ The amount of data returned by each issue. Defaults to ``min``. Change
430
+ to ``full`` to see all issue output.
431
+
432
+ CLI Example:
433
+
434
+ .. code-block:: bash
435
+
436
+ salt myminion github.get_issue_comments 514
437
+ salt myminion github.get_issue 514 repo_name=salt
438
+ """
439
+ comments = gh_issues.get_comments(
440
+ *_get_conn_repo(profile, repo_name), issue_number, since=since
441
+ )
442
+
443
+ ret = {}
444
+ for comment in comments or []:
445
+ comment_id = comment.get("id")
446
+ if output == "full":
447
+ ret[comment_id] = comment
448
+ else:
449
+ ret[comment_id] = {
450
+ "id": comment.get("id"),
451
+ "created_at": comment.get("created_at"),
452
+ "updated_at": comment.get("updated_at"),
453
+ "user_login": comment.get("user").get("login"),
454
+ }
455
+ return ret
456
+
457
+
458
+ def get_issues(
459
+ repo_name=None,
460
+ profile="github",
461
+ milestone=None,
462
+ state="open",
463
+ assignee=None,
464
+ creator=None,
465
+ mentioned=None,
466
+ labels=None,
467
+ sort="created",
468
+ direction="desc",
469
+ since=None,
470
+ output="min",
471
+ per_page=None,
472
+ ):
473
+ """
474
+ Returns information for all issues in a given repository, based on the search options.
475
+
476
+ .. deprecated:: 1.1.0
477
+ Use :py:func:`github_repo.list_issues <saltext.github.modules.github_repo.list_issues>` instead.
478
+
479
+ repo_name
480
+ The name of the repository for which to list issues. This argument is
481
+ required, either passed via the CLI, or defined in the configured
482
+ profile. A ``repo_name`` passed as a CLI argument will override the
483
+ :ghconf:`repo_name` defined in the configured profile, if provided.
484
+
485
+ profile
486
+ The name of the profile configuration to use. Defaults to ``github``.
487
+
488
+ milestone
489
+ The number of a GitHub milestone, or a string of either ``*`` or
490
+ ``none``.
491
+
492
+ If a number is passed, it should refer to a milestone by its number
493
+ field. Use the ``github.get_milestone`` function to obtain a milestone's
494
+ number.
495
+
496
+ If the string ``*`` is passed, issues with any milestone are
497
+ accepted. If the string ``none`` is passed, issues without milestones
498
+ are returned.
499
+
500
+ state
501
+ Indicates the state of the issues to return. Can be either ``open``,
502
+ ``closed``, or ``all``. Default is ``open``.
503
+
504
+ assignee
505
+ Can be the name of a user. Pass in ``none`` (as a string) for issues
506
+ with no assigned user or ``*`` for issues assigned to any user.
507
+
508
+ creator
509
+ The user that created the issue.
510
+
511
+ mentioned
512
+ A user that's mentioned in the issue.
513
+
514
+ labels
515
+ A string of comma separated label names. For example, ``bug,ui,@high``.
516
+
517
+ sort
518
+ What to sort results by. Can be either ``created``, ``updated``, or
519
+ ``comments``. Default is ``created``.
520
+
521
+ direction
522
+ The direction of the sort. Can be either ``asc`` or ``desc``. Default
523
+ is ``desc``.
524
+
525
+ since
526
+ Only issues updated at or after this time are returned. This is a
527
+ timestamp in ISO 8601 format: ``YYYY-MM-DDTHH:MM:SSZ``.
528
+
529
+ output
530
+ The amount of data returned by each issue. Defaults to ``min``. Change
531
+ to ``full`` to see all issue output.
532
+
533
+ per_page
534
+ GitHub paginates data in their API calls. Use this value to increase or
535
+ decrease the number of issues gathered from GitHub, per page. If not set,
536
+ GitHub defaults are used. Maximum is 100.
537
+
538
+ CLI Example:
539
+
540
+ .. code-block:: bash
541
+
542
+ salt myminion github.get_issues my-github-repo
543
+ """
544
+ issues = gh_issues.list_all(
545
+ *_get_conn_repo(profile, repo_name),
546
+ milestone=milestone,
547
+ state=state,
548
+ assignee=assignee,
549
+ creator=creator,
550
+ mentioned=mentioned,
551
+ labels=labels,
552
+ sort=sort,
553
+ direction=direction,
554
+ since=since,
555
+ per_page=per_page,
556
+ )
557
+
558
+ ret = {}
559
+ for issue in issues or []:
560
+ issue_id = issue.get("id")
561
+ if output == "full":
562
+ ret[issue_id] = issue
563
+ else:
564
+ ret[issue_id] = gh_issues.format_issue(issue)
565
+
566
+ return ret
567
+
568
+
569
+ def get_milestones(
570
+ repo_name=None,
571
+ profile="github",
572
+ state="open",
573
+ sort="due_on",
574
+ direction="asc",
575
+ output="min",
576
+ per_page=None,
577
+ ):
578
+ """
579
+ Return information about milestones for a given repository.
580
+
581
+ .. deprecated:: 1.1.0
582
+ Use :py:func:`github_repo.list_milestones <saltext.github.modules.github_repo.list_milestones>` instead.
583
+
584
+ repo_name
585
+ The name of the repository for which to list issues. This argument is
586
+ required, either passed via the CLI, or defined in the configured
587
+ profile. A ``repo_name`` passed as a CLI argument will override the
588
+ :ghconf:`repo_name` defined in the configured profile, if provided.
589
+
590
+ profile
591
+ The name of the profile configuration to use. Defaults to ``github``.
592
+
593
+ state
594
+ The state of the milestone. Either ``open``, ``closed``, or ``all``.
595
+ Default is ``open``.
596
+
597
+ sort
598
+ What to sort results by. Either ``due_on`` or ``completeness``. Default
599
+ is ``due_on``.
600
+
601
+ direction
602
+ The direction of the sort. Either ``asc`` or ``desc``. Default is ``asc``.
603
+
604
+ output
605
+ The amount of data returned by each issue. Defaults to ``min``. Change
606
+ to ``full`` to see all issue output.
607
+
608
+ per_page
609
+ GitHub paginates data in their API calls. Use this value to increase or
610
+ decrease the number of issues gathered from GitHub, per page. If not set,
611
+ GitHub defaults are used.
612
+
613
+ CLI Example:
614
+
615
+ .. code-block:: bash
616
+
617
+ salt myminion github.get_milestones
618
+ """
619
+ milestones = gh_milestones.list_all(
620
+ *_get_conn_repo(profile, repo_name),
621
+ state=state,
622
+ sort=sort,
623
+ direction=direction,
624
+ per_page=per_page,
625
+ )
626
+
627
+ ret = {}
628
+ for milestone in milestones or []:
629
+ milestone_id = milestone.get("id")
630
+ if output == "full":
631
+ ret[milestone_id] = milestone
632
+ else:
633
+ ret[milestone_id] = gh_milestones.format_milestone(milestone)
634
+
635
+ return ret
636
+
637
+
638
+ def get_milestone(number=None, name=None, repo_name=None, profile="github", output="min"):
639
+ """
640
+ Return information about a single milestone in a named repository.
641
+
642
+ .. deprecated:: 1.1.0
643
+ Use :py:func:`github_repo.get_milestone <saltext.github.modules.github_repo.get_milestone>` instead.
644
+
645
+ number
646
+ The number of the milestone to retrieve. If provided, this option
647
+ will be favored over ``name``.
648
+
649
+ name
650
+ The name of the milestone to retrieve.
651
+
652
+ repo_name
653
+ The name of the repository for which to list issues. This argument is
654
+ required, either passed via the CLI, or defined in the configured
655
+ profile. A ``repo_name`` passed as a CLI argument will override the
656
+ :ghconf:`repo_name` defined in the configured profile, if provided.
657
+
658
+ profile
659
+ The name of the profile configuration to use. Defaults to ``github``.
660
+
661
+ output
662
+ The amount of data returned by each issue. Defaults to ``min``. Change
663
+ to ``full`` to see all issue output.
664
+
665
+ CLI Example:
666
+
667
+ .. code-block:: bash
668
+
669
+ salt myminion github.get_milestone 72
670
+ salt myminion github.get_milestone name=my_milestone
671
+ """
672
+ if not (number or name):
673
+ raise CommandExecutionError("Either a milestone 'name' or 'number' must be provided.")
674
+
675
+ ret = {}
676
+
677
+ if number:
678
+ try:
679
+ milestone_data = gh_milestones.get(*_get_conn_repo(profile, repo_name), number)
680
+ except GitHubApiError:
681
+ return ret
682
+ milestone_id = (milestone_data or {}).get("id")
683
+ if milestone_id:
684
+ if output.lower() == "full":
685
+ ret[milestone_id] = milestone_data
686
+ else:
687
+ ret[milestone_id] = gh_milestones.format_milestone(milestone_data)
688
+ return ret
689
+
690
+ milestones = get_milestones(repo_name=repo_name, profile=profile, output=output)
691
+ for key, val in milestones.items():
692
+ if val.get("title") == name:
693
+ ret[key] = val
694
+ return ret
695
+
696
+ return ret
697
+
698
+
699
+ def get_repo_info(repo_name, profile="github", ignore_cache=False):
700
+ """
701
+ Return information for a given repo.
702
+
703
+ .. deprecated:: 1.1.0
704
+ Use :py:func:`github_repo.info <saltext.github.modules.github_repo.info>` instead.
705
+
706
+ repo_name
707
+ The name of the repository.
708
+
709
+ profile
710
+ The name of the profile configuration to use. Defaults to ``github``.
711
+
712
+ CLI Example:
713
+
714
+ .. code-block:: bash
715
+
716
+ salt myminion github.get_repo_info salt
717
+ salt myminion github.get_repo_info salt profile='my-github-profile'
718
+ """
719
+ info = gh_repos.get_info(_get_conn(profile), repo_name, ignore_cache=ignore_cache)
720
+ # The legacy output contained GitHub's deprecated alias fields
721
+ return {
722
+ **info,
723
+ "watchers_count": info["stargazers_count"],
724
+ "watchers": info["stargazers_count"],
725
+ "forks": info["forks_count"],
726
+ "open_issues": info["open_issues_count"],
727
+ }
728
+
729
+
730
+ def get_repo_teams(repo_name, profile="github"):
731
+ """
732
+ Return teams belonging to a repository.
733
+
734
+ .. deprecated:: 1.1.0
735
+ Use :py:func:`github_repo.get_teams <saltext.github.modules.github_repo.get_teams>` instead.
736
+
737
+ repo_name
738
+ The name of the repository from which to retrieve teams.
739
+
740
+ profile
741
+ The name of the profile configuration to use. Defaults to ``github``.
742
+
743
+ CLI Example:
744
+
745
+ .. code-block:: bash
746
+
747
+ salt myminion github.get_repo_teams salt
748
+ salt myminion github.get_repo_teams salt profile='my-github-profile'
749
+ """
750
+ return gh_repos.get_teams(_get_conn(profile), repo_name)
751
+
752
+
753
+ def list_repos(profile="github"):
754
+ """
755
+ List all repositories within the organization. Includes public and private
756
+ repositories within the organization Dependent upon the access rights of
757
+ the profile token.
758
+
759
+ .. deprecated:: 1.1.0
760
+ Use :py:func:`github_org.list_repos <saltext.github.modules.github_org.list_repos>` instead.
761
+
762
+ profile
763
+ The name of the profile configuration to use. Defaults to ``github``.
764
+
765
+ CLI Example:
766
+
767
+ .. code-block:: bash
768
+
769
+ salt myminion github.list_repos
770
+ salt myminion github.list_repos profile='my-github-profile'
771
+ """
772
+ return [repo.name for repo in gh_repos.list_all(_get_conn(profile))]
773
+
774
+
775
+ def list_private_repos(profile="github"):
776
+ """
777
+ List private repositories within the organization. Dependent upon the access
778
+ rights of the profile token.
779
+
780
+ .. deprecated:: 1.1.0
781
+ Use :py:func:`github_org.list_repos <saltext.github.modules.github_org.list_repos>` instead.
782
+
783
+ profile
784
+ The name of the profile configuration to use. Defaults to ``github``.
785
+
786
+ CLI Example:
787
+
788
+ .. code-block:: bash
789
+
790
+ salt myminion github.list_private_repos
791
+ salt myminion github.list_private_repos profile='my-github-profile'
792
+ """
793
+ return [repo.name for repo in gh_repos.list_all(_get_conn(profile)) if repo.private is True]
794
+
795
+
796
+ def list_public_repos(profile="github"):
797
+ """
798
+ List public repositories within the organization.
799
+
800
+ .. deprecated:: 1.1.0
801
+ Use :py:func:`github_org.list_repos <saltext.github.modules.github_org.list_repos>` instead.
802
+
803
+ profile
804
+ The name of the profile configuration to use. Defaults to ``github``.
805
+
806
+ CLI Example:
807
+
808
+ .. code-block:: bash
809
+
810
+ salt myminion github.list_public_repos
811
+ salt myminion github.list_public_repos profile='my-github-profile'
812
+ """
813
+ return [repo.name for repo in gh_repos.list_all(_get_conn(profile)) if repo.private is False]
814
+
815
+
816
+ def add_repo(
817
+ name,
818
+ description=None,
819
+ homepage=None,
820
+ private=None,
821
+ has_issues=None,
822
+ has_wiki=None,
823
+ has_downloads=None,
824
+ auto_init=None,
825
+ gitignore_template=None,
826
+ license_template=None,
827
+ profile="github",
828
+ ):
829
+ """
830
+ Create a new github repository.
831
+
832
+ .. deprecated:: 1.1.0
833
+ Use :py:func:`github_org.add_repo <saltext.github.modules.github_org.add_repo>` instead.
834
+
835
+ name
836
+ The name of the team to be created.
837
+
838
+ description
839
+ The description of the repository.
840
+
841
+ homepage
842
+ The URL with more information about the repository.
843
+
844
+ private
845
+ The visiblity of the repository. Note that private repositories require
846
+ a paid GitHub account.
847
+
848
+ has_issues
849
+ Whether to enable issues for this repository.
850
+
851
+ has_wiki
852
+ Whether to enable the wiki for this repository.
853
+
854
+ has_downloads
855
+ Whether to enable downloads for this repository.
856
+
857
+ auto_init
858
+ Whether to create an initial commit with an empty README.
859
+
860
+ gitignore_template
861
+ The desired language or platform for a .gitignore, e.g "Haskell".
862
+
863
+ license_template
864
+ The desired LICENSE template to apply, e.g "mit" or "mozilla".
865
+
866
+ profile
867
+ The name of the profile configuration to use. Defaults to ``github``.
868
+
869
+ CLI Example:
870
+
871
+ .. code-block:: bash
872
+
873
+ salt myminion github.add_repo 'repo_name'
874
+ """
875
+ try:
876
+ gh_repos.create(
877
+ _get_conn(profile),
878
+ name,
879
+ description=description,
880
+ homepage=homepage,
881
+ private=private,
882
+ has_issues=has_issues,
883
+ has_wiki=has_wiki,
884
+ has_downloads=has_downloads,
885
+ auto_init=auto_init,
886
+ gitignore_template=gitignore_template,
887
+ license_template=license_template,
888
+ )
889
+ return True
890
+ except GitHubApiError:
891
+ log.error("Error creating a repo", exc_info_on_loglevel=logging.DEBUG)
892
+ return False
893
+
894
+
895
+ def edit_repo(
896
+ name,
897
+ description=None,
898
+ homepage=None,
899
+ private=None,
900
+ has_issues=None,
901
+ has_wiki=None,
902
+ has_downloads=None,
903
+ profile="github",
904
+ ):
905
+ """
906
+ Updates an existing Github repository.
907
+
908
+ .. deprecated:: 1.1.0
909
+ Use :py:func:`github_repo.update <saltext.github.modules.github_repo.update>` instead.
910
+
911
+ name
912
+ The name of the team to be created.
913
+
914
+ description
915
+ The description of the repository.
916
+
917
+ homepage
918
+ The URL with more information about the repository.
919
+
920
+ private
921
+ The visiblity of the repository. Note that private repositories require
922
+ a paid GitHub account.
923
+
924
+ has_issues
925
+ Whether to enable issues for this repository.
926
+
927
+ has_wiki
928
+ Whether to enable the wiki for this repository.
929
+
930
+ has_downloads
931
+ Whether to enable downloads for this repository.
932
+
933
+ profile
934
+ The name of the profile configuration to use. Defaults to ``github``.
935
+
936
+ CLI Example:
937
+
938
+ .. code-block:: bash
939
+
940
+ salt myminion github.add_repo 'repo_name'
941
+ """
942
+
943
+ try:
944
+ allow_privacy_change = _get_config_value(profile, "allow_repo_privacy_changes")
945
+ except CommandExecutionError:
946
+ allow_privacy_change = False
947
+
948
+ try:
949
+ gh_repos.update(
950
+ _get_conn(profile),
951
+ name,
952
+ description=description,
953
+ homepage=homepage,
954
+ private=private,
955
+ has_issues=has_issues,
956
+ has_wiki=has_wiki,
957
+ has_downloads=has_downloads,
958
+ allow_privacy_change=allow_privacy_change,
959
+ )
960
+ return True
961
+ except GitHubApiError:
962
+ log.error("Error editing a repo", exc_info_on_loglevel=logging.DEBUG)
963
+ return False
964
+
965
+
966
+ def remove_repo(name, profile="github"):
967
+ """
968
+ Remove a Github repository.
969
+
970
+ .. deprecated:: 1.1.0
971
+ Use :py:func:`github_repo.delete <saltext.github.modules.github_repo.delete>` instead.
972
+
973
+ name
974
+ The name of the repository to be removed.
975
+
976
+ profile
977
+ The name of the profile configuration to use. Defaults to ``github``.
978
+
979
+ CLI Example:
980
+
981
+ .. code-block:: bash
982
+
983
+ salt myminion github.remove_repo 'my-repo'
984
+ """
985
+ conn = _get_conn(profile)
986
+ try:
987
+ gh_repos.get_info(conn, name)
988
+ except CommandExecutionError:
989
+ log.error("Repo %s to be removed does not exist.", name)
990
+ return False
991
+ try:
992
+ gh_repos.delete(conn, name)
993
+ return True
994
+ except GitHubApiError:
995
+ log.error("Error deleting a repo", exc_info_on_loglevel=logging.DEBUG)
996
+ return False
997
+
998
+
999
+ def get_team(name, profile="github"):
1000
+ """
1001
+ Returns the team details if a team with the given name exists, or None
1002
+ otherwise.
1003
+
1004
+ .. deprecated:: 1.1.0
1005
+ Use :py:func:`github_org.get_team <saltext.github.modules.github_org.get_team>` instead.
1006
+
1007
+ name
1008
+ The team name for which to obtain information.
1009
+
1010
+ profile
1011
+ The name of the profile configuration to use. Defaults to ``github``.
1012
+
1013
+ CLI Example:
1014
+
1015
+ .. code-block:: bash
1016
+
1017
+ salt myminion github.get_team 'team_name'
1018
+ """
1019
+ return gh_teams.get(_get_conn(profile), name)
1020
+
1021
+
1022
+ def add_team(
1023
+ name,
1024
+ description=None,
1025
+ repo_names=None,
1026
+ privacy=None,
1027
+ permission=None,
1028
+ profile="github",
1029
+ ):
1030
+ """
1031
+ Create a new Github team within an organization.
1032
+
1033
+ .. deprecated:: 1.1.0
1034
+ Use :py:func:`github_org.add_team <saltext.github.modules.github_org.add_team>` instead.
1035
+
1036
+ name
1037
+ The name of the team to be created.
1038
+
1039
+ description
1040
+ The description of the team.
1041
+
1042
+ repo_names
1043
+ The names of repositories to add the team to.
1044
+
1045
+ privacy
1046
+ The level of privacy for the team, can be ``secret`` or ``closed``.
1047
+
1048
+ permission
1049
+ The default permission for new repositories added to the team, can be
1050
+ ``pull``, ``push`` or ``admin``.
1051
+
1052
+ profile
1053
+ The name of the profile configuration to use. Defaults to ``github``.
1054
+
1055
+ CLI Example:
1056
+
1057
+ .. code-block:: bash
1058
+
1059
+ salt myminion github.add_team 'team_name'
1060
+ """
1061
+ try:
1062
+ gh_teams.create(
1063
+ _get_conn(profile),
1064
+ name,
1065
+ description=description,
1066
+ repo_names=repo_names,
1067
+ privacy=privacy,
1068
+ permission=permission,
1069
+ )
1070
+ return True
1071
+ except GitHubApiError:
1072
+ log.error("Error creating a team", exc_info_on_loglevel=logging.DEBUG)
1073
+ return False
1074
+
1075
+
1076
+ def edit_team(name, description=None, privacy=None, permission=None, profile="github"):
1077
+ """
1078
+ Updates an existing Github team.
1079
+
1080
+ .. deprecated:: 1.1.0
1081
+ Use :py:func:`github_org.edit_team <saltext.github.modules.github_org.edit_team>` instead.
1082
+
1083
+ name
1084
+ The name of the team to be edited.
1085
+
1086
+ description
1087
+ The description of the team.
1088
+
1089
+ privacy
1090
+ The level of privacy for the team, can be ``secret`` or ``closed``.
1091
+
1092
+ permission
1093
+ The default permission for new repositories added to the team, can be
1094
+ ``pull``, ``push`` or ``admin``.
1095
+
1096
+ profile
1097
+ The name of the profile configuration to use. Defaults to ``github``.
1098
+
1099
+ CLI Example:
1100
+
1101
+ .. code-block:: bash
1102
+
1103
+ salt myminion github.edit_team 'team_name' description='Team description'
1104
+ """
1105
+ conn = _get_conn(profile)
1106
+ team = gh_teams.get(conn, name)
1107
+ if not team:
1108
+ log.error("Team %s does not exist", name)
1109
+ return False
1110
+ try:
1111
+ gh_teams.update(
1112
+ conn,
1113
+ team,
1114
+ name,
1115
+ description=description,
1116
+ privacy=privacy,
1117
+ permission=permission,
1118
+ )
1119
+ return True
1120
+ except GitHubNotFoundError:
1121
+ log.error("Resource not found", exc_info_on_loglevel=logging.DEBUG)
1122
+ return False
1123
+
1124
+
1125
+ def remove_team(name, profile="github"):
1126
+ """
1127
+ Remove a github team.
1128
+
1129
+ .. deprecated:: 1.1.0
1130
+ Use :py:func:`github_org.remove_team <saltext.github.modules.github_org.remove_team>` instead.
1131
+
1132
+ name
1133
+ The name of the team to be removed.
1134
+
1135
+ profile
1136
+ The name of the profile configuration to use. Defaults to ``github``.
1137
+
1138
+ CLI Example:
1139
+
1140
+ .. code-block:: bash
1141
+
1142
+ salt myminion github.remove_team 'team_name'
1143
+ """
1144
+ conn = _get_conn(profile)
1145
+ team_info = gh_teams.get(conn, name)
1146
+ if not team_info:
1147
+ log.error("Team %s to be removed does not exist.", name)
1148
+ return False
1149
+ try:
1150
+ gh_teams.delete(conn, team_info)
1151
+ return gh_teams.get(conn, name) is None
1152
+ except GitHubApiError:
1153
+ log.error("Error deleting a team", exc_info_on_loglevel=logging.DEBUG)
1154
+ return False
1155
+
1156
+
1157
+ def list_team_repos(team_name, profile="github", ignore_cache=False):
1158
+ """
1159
+ Gets the repo details for a given team as a dict from repo_name to repo details.
1160
+ Note that repo names are always in lower case.
1161
+
1162
+ .. deprecated:: 1.1.0
1163
+ Use :py:func:`github_org.list_team_repos <saltext.github.modules.github_org.list_team_repos>` instead.
1164
+
1165
+ team_name
1166
+ The name of the team from which to list repos.
1167
+
1168
+ profile
1169
+ The name of the profile configuration to use. Defaults to ``github``.
1170
+
1171
+ ignore_cache
1172
+ Bypasses the use of cached team repos.
1173
+
1174
+ CLI Example:
1175
+
1176
+ .. code-block:: bash
1177
+
1178
+ salt myminion github.list_team_repos 'team_name'
1179
+ """
1180
+ conn = _get_conn(profile)
1181
+ cached_team = gh_teams.get(conn, team_name)
1182
+ if not cached_team:
1183
+ log.error("Team %s does not exist.", team_name)
1184
+ return False
1185
+
1186
+ try:
1187
+ return gh_teams.list_repos(conn, cached_team, ignore_cache=ignore_cache)
1188
+ except GitHubNotFoundError:
1189
+ log.error("Resource not found: %s", cached_team["id"], exc_info_on_loglevel=logging.DEBUG)
1190
+ return {}
1191
+
1192
+
1193
+ def add_team_repo(repo_name, team_name, profile="github", permission=None):
1194
+ """
1195
+ Adds a repository to a team with team_name.
1196
+
1197
+ .. deprecated:: 1.1.0
1198
+ Use :py:func:`github_org.add_team_repo <saltext.github.modules.github_org.add_team_repo>` instead.
1199
+
1200
+ repo_name
1201
+ The name of the repository to add.
1202
+
1203
+ team_name
1204
+ The name of the team of which to add the repository.
1205
+
1206
+ profile
1207
+ The name of the profile configuration to use. Defaults to ``github``.
1208
+
1209
+ permission
1210
+ The permission for team members within the repository, can be ``pull``,
1211
+ ``push`` or ``admin``. If not specified, the default permission specified on
1212
+ the team will be used.
1213
+
1214
+ CLI Example:
1215
+
1216
+ .. code-block:: bash
1217
+
1218
+ salt myminion github.add_team_repo 'my_repo' 'team_name'
1219
+ """
1220
+ conn = _get_conn(profile)
1221
+ team_info = gh_teams.get(conn, team_name)
1222
+ if not team_info:
1223
+ log.error("Team %s does not exist", team_name)
1224
+ return False
1225
+ try:
1226
+ gh_teams.add_repo(conn, team_info, repo_name, permission=permission)
1227
+ except GitHubNotFoundError:
1228
+ log.error("Resource not found: %s", team_info["id"], exc_info_on_loglevel=logging.DEBUG)
1229
+ return False
1230
+ except CommandExecutionError as err:
1231
+ log.error(str(err), exc_info_on_loglevel=logging.DEBUG)
1232
+ return False
1233
+ return True
1234
+
1235
+
1236
+ def remove_team_repo(repo_name, team_name, profile="github"):
1237
+ """
1238
+ Removes a repository from a team with team_name.
1239
+
1240
+ .. deprecated:: 1.1.0
1241
+ Use :py:func:`github_org.remove_team_repo <saltext.github.modules.github_org.remove_team_repo>` instead.
1242
+
1243
+ repo_name
1244
+ The name of the repository to remove.
1245
+
1246
+ team_name
1247
+ The name of the team of which to remove the repository.
1248
+
1249
+ profile
1250
+ The name of the profile configuration to use. Defaults to ``github``.
1251
+
1252
+ CLI Example:
1253
+
1254
+ .. code-block:: bash
1255
+
1256
+ salt myminion github.remove_team_repo 'my_repo' 'team_name'
1257
+ """
1258
+ conn = _get_conn(profile)
1259
+ team_info = gh_teams.get(conn, team_name)
1260
+ if not team_info:
1261
+ log.error("Team %s does not exist", team_name)
1262
+ return False
1263
+ try:
1264
+ return gh_teams.remove_repo(conn, team_info, repo_name)
1265
+ except GitHubNotFoundError:
1266
+ log.error("Resource not found: %s", team_info["id"], exc_info_on_loglevel=logging.DEBUG)
1267
+ return False
1268
+
1269
+
1270
+ def list_team_members(team_name, profile="github", ignore_cache=False):
1271
+ """
1272
+ Gets the names of team members in lower case.
1273
+
1274
+ .. deprecated:: 1.1.0
1275
+ Use :py:func:`github_org.list_team_members <saltext.github.modules.github_org.list_team_members>` instead.
1276
+
1277
+ team_name
1278
+ The name of the team from which to list members.
1279
+
1280
+ profile
1281
+ The name of the profile configuration to use. Defaults to ``github``.
1282
+
1283
+ ignore_cache
1284
+ Bypasses the use of cached team members.
1285
+
1286
+ CLI Example:
1287
+
1288
+ .. code-block:: bash
1289
+
1290
+ salt myminion github.list_team_members 'team_name'
1291
+ """
1292
+ conn = _get_conn(profile)
1293
+ cached_team = gh_teams.get(conn, team_name)
1294
+ if not cached_team:
1295
+ log.error("Team %s does not exist.", team_name)
1296
+ return False
1297
+
1298
+ try:
1299
+ return gh_teams.list_members(conn, cached_team, ignore_cache=ignore_cache)
1300
+ except GitHubNotFoundError:
1301
+ log.error("Resource not found: %s", cached_team["id"], exc_info_on_loglevel=logging.DEBUG)
1302
+ return []
1303
+
1304
+
1305
+ def list_members_without_mfa(profile="github", ignore_cache=False):
1306
+ """
1307
+ List all members (in lower case) without MFA turned on.
1308
+
1309
+ .. deprecated:: 1.1.0
1310
+ Deprecated without replacement, along with the per-team MFA
1311
+ enforcement of the ``github.team_present`` state. Require 2FA
1312
+ organization-wide in the GitHub settings instead.
1313
+
1314
+ profile
1315
+ The name of the profile configuration to use. Defaults to ``github``.
1316
+
1317
+ ignore_cache
1318
+ Bypasses the use of cached team repos.
1319
+
1320
+ CLI Example:
1321
+
1322
+ .. code-block:: bash
1323
+
1324
+ salt myminion github.list_members_without_mfa
1325
+ """
1326
+ return gh_members.list_without_mfa(_get_conn(profile), ignore_cache=ignore_cache)
1327
+
1328
+
1329
+ def is_team_member(name, team_name, profile="github"):
1330
+ """
1331
+ Returns True if the github user is in the team with team_name, or False
1332
+ otherwise.
1333
+
1334
+ .. deprecated:: 1.1.0
1335
+ Use :py:func:`github_org.is_team_member <saltext.github.modules.github_org.is_team_member>` instead.
1336
+
1337
+ name
1338
+ The name of the user whose membership to check.
1339
+
1340
+ team_name
1341
+ The name of the team to check membership in.
1342
+
1343
+ profile
1344
+ The name of the profile configuration to use. Defaults to ``github``.
1345
+
1346
+ CLI Example:
1347
+
1348
+ .. code-block:: bash
1349
+
1350
+ salt myminion github.is_team_member 'user_name' 'team_name'
1351
+ """
1352
+ # list_team_members returns False for missing teams
1353
+ return name.lower() in (list_team_members(team_name, profile=profile) or [])
1354
+
1355
+
1356
+ def add_team_member(name, team_name, profile="github"):
1357
+ """
1358
+ Adds a team member to a team with team_name.
1359
+
1360
+ .. deprecated:: 1.1.0
1361
+ Use :py:func:`github_org.add_team_member <saltext.github.modules.github_org.add_team_member>` instead.
1362
+
1363
+ name
1364
+ The name of the team member to add.
1365
+
1366
+ team_name
1367
+ The name of the team of which to add the user.
1368
+
1369
+ profile
1370
+ The name of the profile configuration to use. Defaults to ``github``.
1371
+
1372
+ CLI Example:
1373
+
1374
+ .. code-block:: bash
1375
+
1376
+ salt myminion github.add_team_member 'user_name' 'team_name'
1377
+ """
1378
+ conn = _get_conn(profile)
1379
+ team_info = gh_teams.get(conn, team_name)
1380
+ if not team_info:
1381
+ log.error("Team %s does not exist", team_name)
1382
+ return False
1383
+ try:
1384
+ gh_teams.add_member(conn, team_info, name)
1385
+ except GitHubNotFoundError:
1386
+ log.error("Resource not found: %s", team_info["id"], exc_info_on_loglevel=logging.DEBUG)
1387
+ return False
1388
+ except GitHubApiError:
1389
+ log.error("Error in adding a member to a team", exc_info_on_loglevel=logging.DEBUG)
1390
+ return False
1391
+ return True
1392
+
1393
+
1394
+ def remove_team_member(name, team_name, profile="github"):
1395
+ """
1396
+ Removes a team member from a team with team_name.
1397
+
1398
+ .. deprecated:: 1.1.0
1399
+ Use :py:func:`github_org.remove_team_member <saltext.github.modules.github_org.remove_team_member>` instead.
1400
+
1401
+ name
1402
+ The name of the team member to remove.
1403
+
1404
+ team_name
1405
+ The name of the team from which to remove the user.
1406
+
1407
+ profile
1408
+ The name of the profile configuration to use. Defaults to ``github``.
1409
+
1410
+ CLI Example:
1411
+
1412
+ .. code-block:: bash
1413
+
1414
+ salt myminion github.remove_team_member 'user_name' 'team_name'
1415
+ """
1416
+ conn = _get_conn(profile)
1417
+ team_info = gh_teams.get(conn, team_name)
1418
+ if not team_info:
1419
+ log.error("Team %s does not exist", team_name)
1420
+ return False
1421
+ try:
1422
+ return gh_teams.remove_member(conn, team_info, name)
1423
+ except GitHubNotFoundError:
1424
+ log.error("Resource not found: %s", team_info["id"], exc_info_on_loglevel=logging.DEBUG)
1425
+ return False
1426
+
1427
+
1428
+ def list_teams(profile="github", ignore_cache=False):
1429
+ """
1430
+ Lists all teams with the organization.
1431
+
1432
+ .. deprecated:: 1.1.0
1433
+ Use :py:func:`github_org.list_teams <saltext.github.modules.github_org.list_teams>` instead.
1434
+
1435
+ profile
1436
+ The name of the profile configuration to use. Defaults to ``github``.
1437
+
1438
+ ignore_cache
1439
+ Bypasses the use of cached teams.
1440
+
1441
+ CLI Example:
1442
+
1443
+ .. code-block:: bash
1444
+
1445
+ salt myminion github.list_teams
1446
+ """
1447
+ return gh_teams.list_all(_get_conn(profile), ignore_cache=ignore_cache)
1448
+
1449
+
1450
+ def get_prs(
1451
+ repo_name=None,
1452
+ profile="github",
1453
+ state="open",
1454
+ head=None,
1455
+ base=None,
1456
+ sort="created",
1457
+ direction="desc",
1458
+ output="min",
1459
+ per_page=None,
1460
+ ):
1461
+ """
1462
+ Returns information for all pull requests in a given repository, based on
1463
+ the search options provided.
1464
+
1465
+ .. deprecated:: 1.1.0
1466
+ Use :py:func:`github_repo.list_pulls <saltext.github.modules.github_repo.list_pulls>` instead.
1467
+
1468
+ repo_name
1469
+ The name of the repository for which to list pull requests. This
1470
+ argument is required, either passed via the CLI, or defined in the
1471
+ configured profile. A ``repo_name`` passed as a CLI argument will
1472
+ override the ``repo_name`` defined in the configured profile, if
1473
+ provided.
1474
+
1475
+ profile
1476
+ The name of the profile configuration to use. Defaults to ``github``.
1477
+
1478
+ state
1479
+ Indicates the state of the pull requests to return. Can be either
1480
+ ``open``, ``closed``, or ``all``. Default is ``open``.
1481
+
1482
+ head
1483
+ Filter pull requests by head user and branch name in the format of
1484
+ ``user:ref-name``. Example: ``'github:new-script-format'``. Default
1485
+ is ``None``.
1486
+
1487
+ base
1488
+ Filter pulls by base branch name. Example: ``gh-pages``. Default is
1489
+ ``None``.
1490
+
1491
+ sort
1492
+ What to sort results by. Can be either ``created``, ``updated``,
1493
+ ``popularity`` (comment count), or ``long-running`` (age, filtering
1494
+ by pull requests updated within the last month). Default is ``created``.
1495
+
1496
+ direction
1497
+ The direction of the sort. Can be either ``asc`` or ``desc``. Default
1498
+ is ``desc``.
1499
+
1500
+ output
1501
+ The amount of data returned by each pull request. Defaults to ``min``.
1502
+ Change to ``full`` to see all pull request output.
1503
+
1504
+ per_page
1505
+ GitHub paginates data in their API calls. Use this value to increase or
1506
+ decrease the number of pull requests gathered from GitHub, per page. If
1507
+ not set, GitHub defaults are used. Maximum is 100.
1508
+
1509
+ CLI Example:
1510
+
1511
+ .. code-block:: bash
1512
+
1513
+ salt myminion github.get_prs
1514
+ salt myminion github.get_prs base=2016.11
1515
+ """
1516
+ prs = gh_pulls.list_all(
1517
+ *_get_conn_repo(profile, repo_name),
1518
+ state=state,
1519
+ head=head,
1520
+ base=base,
1521
+ sort=sort,
1522
+ direction=direction,
1523
+ per_page=per_page,
1524
+ )
1525
+
1526
+ ret = {}
1527
+ for pr_ in prs or []:
1528
+ pr_id = pr_.get("id")
1529
+ if output == "full":
1530
+ ret[pr_id] = pr_
1531
+ else:
1532
+ ret[pr_id] = gh_pulls.format_pr(pr_)
1533
+
1534
+ return ret
1535
+
1536
+
1537
+ def _resolve_ruleset_params(
1538
+ profile,
1539
+ require_id=False,
1540
+ require_params=False,
1541
+ *,
1542
+ ruleset_type=None,
1543
+ owner=None,
1544
+ repo_name=None,
1545
+ org_name=None,
1546
+ header_dict=None,
1547
+ ruleset_id=None,
1548
+ ruleset_params=None,
1549
+ **_,
1550
+ ):
1551
+ """
1552
+ Helper function that merges CLI parameters with profile configuration
1553
+ defaults for ruleset operations.
1554
+
1555
+ profile
1556
+ The name of the profile configuration to use.
1557
+
1558
+ require_id
1559
+ Require ruleset_id. Defaults to false.
1560
+
1561
+ require_params
1562
+ Require ruleset_params payload. Defaults to false.
1563
+ """
1564
+ ruleset_type = ruleset_type or _get_config_value(profile, "ruleset_type")
1565
+ if ruleset_type not in ("repo", "org"):
1566
+ raise CommandExecutionError(f"Invalid ruleset type: {ruleset_type}")
1567
+
1568
+ # Unset owners fall back to the connection default (the profile's
1569
+ # owner or the token's user) in the ruleset utils.
1570
+ if ruleset_type == "repo":
1571
+ owner = owner or _get_owner(profile)
1572
+ repo_name = repo_name or _get_config_value(profile, "repo_name")
1573
+ else:
1574
+ org_name = org_name or _get_owner(profile)
1575
+
1576
+ # check for optional header_dict
1577
+ try:
1578
+ header_dict = header_dict or _get_config_value(profile, "header_dict")
1579
+ except CommandExecutionError:
1580
+ header_dict = {}
1581
+
1582
+ # verify header_dict is a dict
1583
+ if not isinstance(header_dict, dict):
1584
+ header_dict = {}
1585
+
1586
+ # if ruleset is required, check for ruleset_id
1587
+ if require_id:
1588
+ ruleset_id = ruleset_id or _get_config_value(profile, "ruleset_id")
1589
+
1590
+ # if ruleset_params are required, check for ruleset_params
1591
+ if require_params:
1592
+ ruleset_params = ruleset_params or _get_config_value(profile, "ruleset_params")
1593
+
1594
+ return filter_unset(
1595
+ {
1596
+ "ruleset_type": ruleset_type,
1597
+ "owner": owner,
1598
+ "repo_name": repo_name,
1599
+ "org_name": org_name,
1600
+ "headers": header_dict,
1601
+ "ruleset_id": ruleset_id,
1602
+ "ruleset_params": ruleset_params,
1603
+ }
1604
+ )
1605
+
1606
+
1607
+ def _ruleset_error_ret(err):
1608
+ """
1609
+ Format a :class:`GitHubApiError` into the legacy ruleset return shape.
1610
+ """
1611
+ ret = {"status": err.status, "error": str(err)}
1612
+ if err.data is not None:
1613
+ ret["dict"] = err.data
1614
+ ret["comment"] = f"GitHub Response Status Code: {err}"
1615
+ ret["result"] = False
1616
+ return ret
1617
+
1618
+
1619
+ def get_ruleset(profile="github", **kwargs):
1620
+ """
1621
+ Get information of specific ruleset.
1622
+
1623
+ .. deprecated:: 1.1.0
1624
+ Use :py:func:`github_org.get_ruleset <saltext.github.modules.github_org.get_ruleset>` or
1625
+ :py:func:`github_repo.get_ruleset <saltext.github.modules.github_repo.get_ruleset>` instead.
1626
+
1627
+ profile
1628
+ The name of the profile configuration to use. Defaults to ``github``.
1629
+
1630
+ ruleset_type
1631
+ The type of ruleset. ``repo`` or ``org``.
1632
+
1633
+ ruleset_id
1634
+ Id of the ruleset.
1635
+
1636
+ owner
1637
+ The account owner of the repository.
1638
+
1639
+ repo_name
1640
+ The name of the repo.
1641
+
1642
+ org_name
1643
+ The name of the organization.
1644
+
1645
+ header_dict
1646
+ Headers to pass to Github API.
1647
+
1648
+ CLI Example:
1649
+
1650
+ .. code-block:: bash
1651
+
1652
+ salt myminion github.get_ruleset
1653
+ salt myminion github.get_ruleset ruleset_id=1
1654
+ """
1655
+ params = _resolve_ruleset_params(profile, require_id=True, **kwargs)
1656
+ params.pop("ruleset_params", None)
1657
+ try:
1658
+ return gh_rulesets.get(
1659
+ _get_conn(profile), params.pop("ruleset_id"), params.pop("ruleset_type"), **params
1660
+ )
1661
+ except GitHubApiError as err:
1662
+ return _ruleset_error_ret(err)
1663
+ except CommandExecutionError:
1664
+ return {"result": False, "comment": "Error getting ruleset"}
1665
+
1666
+
1667
+ def delete_ruleset(profile="github", **kwargs):
1668
+ """
1669
+ Delete ruleset
1670
+
1671
+ .. deprecated:: 1.1.0
1672
+ Use :py:func:`github_org.delete_ruleset <saltext.github.modules.github_org.delete_ruleset>` or
1673
+ :py:func:`github_repo.delete_ruleset <saltext.github.modules.github_repo.delete_ruleset>` instead.
1674
+
1675
+ profile
1676
+ The name of the profile configuration to use. Defaults to ``github``.
1677
+
1678
+ ruleset_type
1679
+ The type of ruleset. ``repo`` or ``org``.
1680
+
1681
+ owner
1682
+ The account owner of the repository.
1683
+
1684
+ repo_name
1685
+ The name of the repo.
1686
+
1687
+ ruleset_id
1688
+ Id of the ruleset.
1689
+
1690
+ org_name
1691
+ The name of the organization.
1692
+
1693
+ header_dict
1694
+ Headers to pass to Github API.
1695
+
1696
+ CLI Example:
1697
+
1698
+ .. code-block:: bash
1699
+
1700
+ salt myminion github.delete_ruleset
1701
+ salt myminion github.delete_ruleset ruleset_id=1
1702
+ """
1703
+ params = _resolve_ruleset_params(profile, require_id=True, **kwargs)
1704
+ params.pop("ruleset_params", None)
1705
+ ruleset_id = params.pop("ruleset_id")
1706
+ try:
1707
+ gh_rulesets.delete(_get_conn(profile), ruleset_id, params.pop("ruleset_type"), **params)
1708
+ return {"comment": f"ruleset {ruleset_id} successfully deleted"}
1709
+ except GitHubApiError as err:
1710
+ return _ruleset_error_ret(err)
1711
+ except CommandExecutionError:
1712
+ return {"result": False, "comment": "Error deleting ruleset"}
1713
+
1714
+
1715
+ def update_ruleset(profile="github", **kwargs):
1716
+ """
1717
+ Update ruleset
1718
+
1719
+ .. deprecated:: 1.1.0
1720
+ Use :py:func:`github_org.update_ruleset <saltext.github.modules.github_org.update_ruleset>` or
1721
+ :py:func:`github_repo.update_ruleset <saltext.github.modules.github_repo.update_ruleset>` instead.
1722
+
1723
+ profile
1724
+ The name of the profile configuration to use. Defaults to ``github``.
1725
+
1726
+ ruleset_type
1727
+ The type of ruleset. ``repo`` or ``org``.
1728
+
1729
+ ruleset_id
1730
+ Id of the ruleset.
1731
+
1732
+ owner
1733
+ The account owner of the repository.
1734
+
1735
+ repo_name
1736
+ The name of the repo.
1737
+
1738
+ org_name
1739
+ The name of the organization.
1740
+
1741
+ header_dict
1742
+ headers to pass to Github API.
1743
+
1744
+ ruleset_params
1745
+ The updated ruleset definition.
1746
+
1747
+ CLI Example:
1748
+
1749
+ .. code-block:: bash
1750
+
1751
+ salt myminion github.update_ruleset
1752
+ salt myminion github.update_ruleset ruleset_id=1
1753
+ """
1754
+ params = _resolve_ruleset_params(profile, require_id=True, require_params=True, **kwargs)
1755
+ ruleset_id = params.pop("ruleset_id")
1756
+ ruleset_params = params.pop("ruleset_params")
1757
+ gh_rulesets.check_params(ruleset_params)
1758
+ try:
1759
+ return gh_rulesets.update(
1760
+ _get_conn(profile),
1761
+ ruleset_id,
1762
+ ruleset_params,
1763
+ params.pop("ruleset_type"),
1764
+ **params,
1765
+ )
1766
+ except GitHubApiError as err:
1767
+ return _ruleset_error_ret(err)
1768
+ except CommandExecutionError:
1769
+ return {"result": False, "comment": "Error updating ruleset"}
1770
+
1771
+
1772
+ def add_ruleset(profile="github", **kwargs):
1773
+ """
1774
+ Add ruleset
1775
+
1776
+ .. deprecated:: 1.1.0
1777
+ Use :py:func:`github_org.add_ruleset <saltext.github.modules.github_org.add_ruleset>` or
1778
+ :py:func:`github_repo.add_ruleset <saltext.github.modules.github_repo.add_ruleset>` instead.
1779
+
1780
+ profile
1781
+ The name of the profile configuration to use. Defaults to ``github``.
1782
+
1783
+ ruleset_type
1784
+ The type of ruleset. ``repo`` or ``org``.
1785
+
1786
+ owner
1787
+ The account owner of the repository.
1788
+
1789
+ repo_name
1790
+ The name of the repo.
1791
+
1792
+ org_name
1793
+ The name of the organization.
1794
+
1795
+ header_dict
1796
+ headers to pass to Github API.
1797
+
1798
+ ruleset_params
1799
+ The ruleset definition. Must contain at least ``name`` and
1800
+ ``enforcement``.
1801
+
1802
+ CLI Example:
1803
+
1804
+ .. code-block:: bash
1805
+
1806
+ salt myminion github.add_ruleset
1807
+ """
1808
+ params = _resolve_ruleset_params(profile, require_params=True, **kwargs)
1809
+ params.pop("ruleset_id", None)
1810
+ ruleset_params = params.pop("ruleset_params")
1811
+ gh_rulesets.check_params(ruleset_params, required={"name", "enforcement"})
1812
+ try:
1813
+ return gh_rulesets.create(
1814
+ _get_conn(profile), ruleset_params, params.pop("ruleset_type"), **params
1815
+ )
1816
+ except GitHubApiError as err:
1817
+ return _ruleset_error_ret(err)
1818
+ except CommandExecutionError:
1819
+ return {"result": False, "comment": "Error adding ruleset"}
1820
+
1821
+
1822
+ def list_rulesets(profile="github", *, per_page=None, **kwargs):
1823
+ """
1824
+ List rulesets
1825
+
1826
+ .. deprecated:: 1.1.0
1827
+ Use :py:func:`github_org.list_rulesets <saltext.github.modules.github_org.list_rulesets>` or
1828
+ :py:func:`github_repo.list_rulesets <saltext.github.modules.github_repo.list_rulesets>` instead.
1829
+
1830
+ profile
1831
+ The name of the profile configuration to use. Defaults to ``github``.
1832
+
1833
+ ruleset_type
1834
+ The type of ruleset. ``repo`` or ``org``.
1835
+
1836
+ owner
1837
+ The account owner of the repository.
1838
+
1839
+ repo_name
1840
+ The name of the repo.
1841
+
1842
+ org_name
1843
+ The name of the organization.
1844
+
1845
+ header_dict
1846
+ headers to pass to Github API.
1847
+
1848
+ per_page
1849
+ number of returned results (max 100).
1850
+
1851
+ CLI Example:
1852
+
1853
+ .. code-block:: bash
1854
+
1855
+ salt myminion github.list_rulesets
1856
+ """
1857
+ params = _resolve_ruleset_params(profile, **kwargs)
1858
+ params.pop("ruleset_id", None)
1859
+ params.pop("ruleset_params", None)
1860
+ try:
1861
+ per_page = per_page if per_page is not None else _get_config_value(profile, "per_page")
1862
+ except CommandExecutionError:
1863
+ per_page = None
1864
+
1865
+ try:
1866
+ rulesets = gh_rulesets.list_all(
1867
+ _get_conn(profile), params.pop("ruleset_type"), per_page=per_page, **params
1868
+ )
1869
+ return {"rulesets": rulesets or None}
1870
+ except GitHubApiError as err:
1871
+ return _ruleset_error_ret(err)
1872
+ except CommandExecutionError:
1873
+ return {"result": False, "comment": "Error getting rulesets"}