File: base_github_manager.py

package info (click to toggle)
azure-functions-devops-build 0.0.22-6
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 556 kB
  • sloc: python: 2,422; sh: 12; makefile: 8
file content (30 lines) | stat: -rw-r--r-- 1,155 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from msrest.service_client import ServiceClient
from msrest import Configuration

class BaseGithubManager(object):

    def __init__(self, base_url='https://api.github.com', pat=None):
        """Inits UserManager as to be able to send the right requests"""
        self._pat = pat
        self._config = Configuration(base_url=base_url)
        self._client = ServiceClient(None, self._config)

    def construct_github_request_header(self, pat=None):
        headers = {
            "Accept": "application/vnd.github.v3+json"
        }

        if pat:
            headers["Authorization"] = "token {pat}".format(pat=pat)
        elif self._pat:
            headers["Authorization"] = "token {pat}".format(pat=self._pat)

        return headers

    def close_connection(self):
        self._client.close()