1 Star 0 Fork 2

PersonalSummary/gitlab_sync

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
contribute
Sync branch
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README

gitlab_code_update脚本介绍

一、环境准备

  • 权限要求

    gitlab的用户必须要有maintainer及以上的权限,否则无法上传代码

  • 主机环境

    Ubuntu系统

  • Python版本要求

    python3.8以上

  • python-gitlab模块安装

    pip install --upgrade python-gitlab
    

二、脚本使用介绍

2.1 使用前准备

  • ssh配置

    必须提前将本地ssh的public-key内容添加到gitlab账号下,具体操作不介绍,百度上很多

  • git配置

    执行如下命令,配置好本地git

    git config --global user.name "yourname"
    git config --global user.email "your-email-address"
    git config --global core.editor vim
    git config --global credential.helper store
    git config --global http.sslverify false
    

    本地下载gitlab任意一个仓,如果没有自行创建一个仓,如果Ubunut是首次访问该gitlab会要求输入账号和密码

    test@pc220522:~/test$ git clone https://isrc.iscas.ac.cn/gitlab/riscv/polyosmobile/gitlab_code_update.git
    Cloning into 'gitlab_code_update'...
    Username for 'https://isrc.iscas.ac.cn': wen_fei # 输入gitlab的用户名
    Password for 'https://wen_fei@isrc.iscas.ac.cn': # 输入gitlab的密码
    remote: Enumerating objects: 65, done.
    remote: Counting objects: 100% (65/65), done.
    remote: Compressing objects: 100% (64/64), done.
    remote: Total 65 (delta 32), reused 0 (delta 0), pack-reused 0
    Unpacking objects: 100% (65/65), done.
    

    结束后检查~/.git-credentials中是否出现了如下的一条记录,如果没有可以手动创建该文件并手动添加进去

    https://user_name:passwd@ip
    
    # 样例
    https://zhang_san:123456aA@gitee.com
    https://zhang_san:123456aA@192.169.1.100
    
  • repo首次下载配置

    如果Ubuntu是首次使用repo下载代码,则先使用repo配置一下环境,因为有一个测试颜色输出,直接输入y回车即可

    test@pc220522:~/test$ mkdir -p ~/test && cd ~/test
    test@pc220522:~/test$ repo init -u https://gitee.com/openharmony/manifest.git -b master --no-repo-verify
    
    Your identity is: wenfei <wenfei@163.com>
    If you want to change this, please re-run 'repo init' with --config-name
    
    Testing colorized output (for 'repo diff', 'repo status'):
      black    red      green    yellow   blue     magenta   cyan     white
      bold     dim      ul       reverse
    Enable color display in this user account (y/N)? y # 输入y然后回车
    
    repo has been initialized in /home/test/test
    

2.2 脚本配置

2.2.1 Access Tokens配置

  • 登录到gitlab后点击个人头像选择Edit profile

  • 左侧点击Access Tokens

  • 在右侧的Token name内随便填写一个名字

  • 下面的Expiration date日期自行配置表示创建的Access Tokens有效期时间

  • Select scopes下面的所有选项全部勾选,表示python-gitlab通过Access Tokens能获取哪些权限

  • 点击下方的Create personal access token按钮创建Access Tokens

  • 将上方的Your new personal access token下面的字符串记录下来,离开该界面后就找不回来了,就得重新申请

    点击小眼睛就能看到Access Tokens的值,点击后面的小电池符号就能复制

  • 打开脚本main.py,在最下方的if __name__ == '__main__':里添加一个变量保存Access Tokens的值

    isrc_tokenid = "glpat-zzQNqTiVAnc5zsyMe7D2"
    

2.2.2 gitlab同步ohos官方代码

  • 变量gitlab_url,该变量必须定义

    表示gitlab的链接

  • 变量main_group,该变量必须定义

    表示代码同步到指定的group下面,如果没有则创建

  • 变量sub_group,默认为None

    表示代码通过到指定main_group下面的某个sub_group内,如果没有则创建,该值默认是None

  • 变量src_url,默认是OpenHarmony的链接

    要同步代码manifest所在的链接

  • 变量branch,默认是master分支

    要同步的xml所在的branch,同时会将同步的代码放到gitlab该branch下

  • 变量xml,默认是default.xml

    要同步代码的xml

  • 变量id,默认为None

    将代码同步到指定id的group里,同时也会匹配name,只有name和id同时满足则将代码同步到该group下,否则新建group

# 参考配置
if __name__ == '__main__':
    warnings.filterwarnings('ignore')
    isrc_tokenid = "glpat-zzQNqTiVAnc5zsyMe7D2"
    ohos_branch = "OpenHarmony-3.2-Beta2"
    gitlab_url = "https://isrc.iscas.ac.cn/gitlab/"
    main_group = "ohos_qemu"
    gitlab_upload_by_url(gitlab_url=gitlab_url,
                         token=isrc_tokenid,
                         main_group=main_group,
                         sub_group=None,
                         branch=ohos_branch,
                         id=20666)

2.2.3 其他说明

鸿蒙部分仓不能通过python-gitlab配置,放在main.py脚本最开始的ext_list列表中

原因如下:

  • kernel仓由于太大经常因为网络原因导致下载出错,建议手动配置

  • 其他仓因为OpenHarmony官方仓原因无法通过python-gitlab配置,必须手动配置,目前对应仓名如下

    third_party_f2fs-tools
    update_updater
    utils_memory
    utils_native
    

2.2.4 脚本执行

配置好上面所有步骤后直接运行main.py即可

./main.py

三、脚本代码介绍

​ 脚本代码持续更新中

Empty file

About

一键同步ohos仓到gitlab expand collapse
Cancel

Releases

No release

Contributors

All

Language(Optional)

Activities

1年前推送了新的 calc 分支
1年前推送了新的提交到 OpenHarmony 分支,bb68ade...c11b9c5
1年前推送了新的提交到 OpenHarmony 分支,18d742a...bb68ade
1年多前推送了新的提交到 OpenHarmony 分支,7142d6a...18d742a
1年多前推送了新的提交到 android 分支,c7e8c03...4d472bc
Load More
can not load any more
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/personal-summary/gitlab_sync.git
git@gitee.com:personal-summary/gitlab_sync.git
personal-summary
gitlab_sync
gitlab_sync
master

Search