'How can I check if a given file is present in a Github repository using PyGithub?

file path = repo_name/abc/xyz.yml

repo (is the git repo object)

I want to be able to check if the repo consists of the file by returning a Boolean.

something like:

def fileInRepo(repo, filePath):
   if filePath in repo.files:
      return true
   else:
      return false


Solution 1:[1]

I had a problem like yours and I resolved it using this script.

    import re
    import requests
    from bs4 import BeautifulSoup

    def check_script(self, git_repo_link: str, name: str) -> bool:
        try:
            r = requests.get(git_repo_link)
            html_doc = r.text
            soup = BeautifulSoup(html_doc)
            file = soup.find_all(title=re.compile(name))
            if file:
                return True
            else:
                return False
        except Exception:
            return False

Hope this is helpful for you. Thank you.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Venus713