def api_contributors(reponame): hit = '{0}-contributors'.format(reponame) entries = cache.get(hit) if entries is None: repo = Repository(reponame) commits = [ (x.author.name) for x in repo.log(repo.head.target.hex) if len(x.parents) == 1 ] entries = Counter(commits).items() cache.set(hit, entries, app.config['CACHE_TIME']); return jsonify(entries);
def api_activity(reponame): hit = '{0}-activity'.format(reponame) entries = cache.get(hit) if entries is None: repo = Repository(reponame) commits = [x for x in repo.log(repo.head.target.hex)] data = [utils.to_date(c.commit_time).strftime("%Y/%m/%d") for c in commits] data_sorted = sorted(Counter(data).items()) entries = [{'date': k, 'commits': v} for k, v in data_sorted] cache.set(hit, entries, app.config['CACHE_TIME']); return jsonify(activity=entries);
def isbatch(self,d): try: self.repository = Repository(d) return True except (git.NoSuchPathError,git.InvalidGitRepositoryError): return False
async def test_parsing(event_loop, change: Change, expected: List[FixedByTag]): async with Repository(change.repository) as repo: fixes = await repo.parse_commit_messages(change) change.__repr__() for fix in fixes: fix.__repr__() assert fixes == expected
def bumpRelease() -> None: """ Increment the release candidate version. """ repository = Repository() if repository.is_dirty(): warning("working copy is dirty") version = currentVersion() if version.release_candidate is None: error(f"current version is not a release candidate: {version}", 1) branch = releaseBranch(repository, version) if repository.head.ref != branch: error( f'working copy is on branch "{repository.head.ref}", ' f'not release branch "{branch}"', 1, ) incrementVersion(candidate=True) version = currentVersion() print("New release candidate version:", version.public())
def startRelease() -> None: """ Start a new release: * Increment the current version to a new release candidate version. * Create a corresponding branch. * Switch to the new branch. """ repository = Repository() if repository.head.ref != repository.heads.master: error( f"working copy is from non-master branch: {repository.head.ref}", 1 ) if repository.is_dirty(): warning("working copy is dirty") version = currentVersion() if version.release_candidate is not None: error(f"current version is already a release candidate: {version}", 1) incrementVersion(candidate=True) version = currentVersion() print(f"New release candidate version: {version.public()}") branch = createReleaseBranch(repository, version) branch.checkout() print("Next steps (to be done manually):") print(" • Commit version changes to the new release branch:", branch) print(" • Push the release branch to GitHub") print(" • Open a pull request on GitHub from the release branch")
async def update_project(self, name: str, since: Optional[str] = None) -> None: async with Repository(name) as repo: changes = await repo.new_changes(since=since) for change in changes: log.info("Checking changes for relevant tags: '%s'", change) # check commit message fixes = await repo.parse_commit_messages(change) for fix in fixes: # do jira magic self.jira_closer.run(fix)
def commits(reponame, revspec = None): repo = Repository(reponame) if revspec != None: rev = repo.revparse_single(revspec) formatter = HtmlFormatter(linenos='inline') diffs = [] for parent in rev.parents: try: data = parent.tree.diff(rev.tree).patch diffs.append(highlight(data, DiffLexer(), formatter)) except: pass return render_template("objects/commit.html", repo= repo, rev = rev, diffs = diffs) log = repo.log(repo.head.target.hex) page = int(request.args.get('page', 0)) revs = islice(log, 20*page, 20*(page+1)) return render_template("objects/commits.html", repo = repo, revs = list(revs), page=page)
def main_normal(): # Parse arguments repodir = sys.argv[1] if len(sys.argv) > 1 else os.getcwd() # Show main window try: repo = Repository(repodir) except GitError: repo = None app = StupidGitApp() app.InitApp() app.OpenRepo(repo) app.MainLoop()
def publishRelease(final: bool, test: bool = False) -> None: """ Publish the current version. """ repository = Repository() if repository.is_dirty(): error("working copy is dirty", 1) version = currentVersion() if version.release_candidate is None: error(f"current version is not a release candidate: {version}", 1) branch = releaseBranch(repository, version) if repository.head.ref != branch: error( f'working copy is on branch "{repository.head.ref}", ' f'not release branch "{branch}"', 1, ) incrementVersion(candidate=False) version = currentVersion() versonFile = Path(__file__).parent / "src" / "klein" / "_version.py" repository.index.add(str(versonFile)) repository.index.commit(f"Update version to {version}") tagName = releaseTagName(version) if tagName in repository.tags: tag = repository.tags[tagName] message = f"Release tag already exists: {tagName}" if tag.commit != repository.head.ref.commit: error(message, 1) else: print(message) else: print("Creating release tag:", tagName) tag = repository.create_tag( tagName, ref=branch, message=f"Tag release {version.public()}" ) print("Pushing tag to origin:", tag) repository.remotes.origin.push(refspec=tag.path) distribute(repository, tag, test=test)
def refs(reponame): repo = Repository(reponame) refs = repo.listall_references() branch_ref_id = 'refs/heads/' branch_entries = [] for r in refs: if r.startswith(branch_ref_id): branch = repo.lookup_reference(r).resolve() branch_entries.append((branch, repo[branch.target])) def comp(x): try: return int(x[1].commit_time) except: return -1 branches = sorted(branch_entries, key=comp, reverse=True) tag_ref_id = 'refs/tags/' tag_entries = [] for r in refs: if r.startswith(tag_ref_id): try: tag = repo[repo.lookup_reference(r).target] tag_entries.append((tag, repo[tag.target])) except: tag = repo.lookup_reference(r) tag_entries.append((tag, repo[tag.target])) tags = sorted(tag_entries, key=comp, reverse=True) regex = re.compile('refs/.*/pr/.*') pulls = [] for r in refs: if regex.match(r): pull = repo.lookup_reference(r).resolve() pulls.append((pull, repo[pull.target])) pull_requests = sorted(pulls, key=comp, reverse=True) return render_template("refs.html", repo = repo, branches = branches, tags = tags, pull_requests = pull_requests)
############################################################################# import asyncio import pytest from typing import List from git import Repository, Change, FixedByTag from logger import logger from git.repository import Version log = logger('test') # make sure we have a checkout, otherwise this fails loop = asyncio.get_event_loop() for repo_name in ('qt/qtbase', 'qt/qtdeclarative', 'qt/qtdatavis3d', 'yocto/meta-qt5', 'qt/tqtc-qt5'): loop.run_until_complete(Repository(repo_name)._check_repo()) dev_branch_version = "5.14.0" @pytest.mark.parametrize("branch,expected,branches,tags", [ ('dev', '5.12.0', ['5.10', '5.11', '5.11.0', '5.11.1', 'dev'], [ 'v5.11.0', 'v5.11.0-alpha1', 'v5.11.0-beta1', 'v5.11.0-beta2', 'v5.11.0-beta3', 'v5.11.0-beta4', 'v5.11.0-rc1', 'v5.11.0-rc2', 'v5.11.1' ]), ('wip/myfeature', None, ['5.10', '5.11', '5.11.0', '5.11.1', 'dev'], [ 'v5.11.0', 'v5.11.0-alpha1', 'v5.11.0-beta1', 'v5.11.0-beta2', 'v5.11.0-beta3', 'v5.11.0-beta4', 'v5.11.0-rc1', 'v5.11.0-rc2', 'v5.11.1' ]),
def MacOpenFile(self, filename): try: repo = Repository(filename) self.OpenRepo(repo) except GitError: pass