当前位置: 首页>>代码示例>>Python>>正文


Python Gittle.get_previous_commit方法代码示例

本文整理汇总了Python中gittle.Gittle.get_previous_commit方法的典型用法代码示例。如果您正苦于以下问题:Python Gittle.get_previous_commit方法的具体用法?Python Gittle.get_previous_commit怎么用?Python Gittle.get_previous_commit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gittle.Gittle的用法示例。


在下文中一共展示了Gittle.get_previous_commit方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: handle

# 需要导入模块: from gittle import Gittle [as 别名]
# 或者: from gittle.Gittle import get_previous_commit [as 别名]
    def handle(self, *args, **options):
        projects = Project.objects.all()

        for project in projects:
            print('Checking {0} for new commits'.format(project))
            if project.git_url:
                repo_path = '/tmp/' + project.slug
                try:
                    repo = Gittle(repo_path, project.git_url)
                    repo.pull()
                except:
                    try:
                        repo = Gittle.clone(project.git_url, repo_path)
                    except:
                        # put some logging here
                        repo = None
                if repo:
                    new_commits = []
                    for commit in repo.commit_info():
                        try:
                            prev_commit = repo.get_previous_commit(commit['sha'])
                            time = (datetime.fromtimestamp(commit['time']) + timedelta(hours=commit['timezone']/(60*60))).replace(tzinfo=pytz.utc)
                            try:
                                user_author = get_user_model().objects.get(email=commit['author']['email'])
                                string_author = None
                            except:
                                string_author = commit['author']['name']
                                user_author = None

                            summary = commit['message'].split('\n')[0][:45]
                            pcommit = ProjectCommit.objects.create(
                                project=project,
                                chash=commit['sha'],
                                message=commit['message'],
                                summary=summary,
                                user_author=user_author,
                                string_author=string_author,
                                created=time,
                                time=time,
                                diff=repo.diff(commit['sha'], prev_commit).next()['diff']
                            )
                            print(pcommit, ' added.')
                            new_commits.append(pcommit)
                        except:
                            pass
开发者ID:Code4Maine,项目名称:beehve,代码行数:47,代码来源:update_project_repos.py


注:本文中的gittle.Gittle.get_previous_commit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。