How to use github cli to auto pull all newly created or updated repos to local pc

huangapple go评论71阅读模式
英文:

How to use github cli to auto pull all newly created or updated repos to local pc

问题

如何使用 GitHub CLI 自动将所有新创建或更新的存储库拉取到本地计算机?

我认为我需要监听新存储库的创建/更新并拉取这些存储库。如何使用 CLI 进行操作?

如果无法监听,我需要将最新的 100 个存储库拉取到本地计算机。如何操作?

我尝试过 https://api.github.com/users/xxxx/repos?per_page=100。它以字母顺序返回。

我使用以下代码:

#!/bin/sh
cat repolist.txt | while read line
do
  REPOSRC=$line
  LOCALREPO=$line

  # 我们以这种方式进行操作,以便稍后可以将其从仅 Git 抽象出来
  LOCALREPO_VC_DIR=$LOCALREPO/.git

  if [ ! -d $LOCALREPO_VC_DIR ]
  then
    cd ~/xxxx
    gh repo clone $REPOSRC
    cd ~
  else
    cd ~
    gh repo sync $REPOSRC -s $REPOSRC
  fi
done
# 结束
英文:

How to use github cli to auto pull all newly created or updated repos to local pc?

I think I need to listen for new repo creation/updation and pull the repos. How to do it with cli?

If can't listen, I need to pull latest 100 repos to local machiene. How to do it?

I tried https://api.github.com/users/xxxx/repos?per_page=100. It gives in alphabetical order.

I use following code

 #!/bin/sh                                                                       
    cat repolist.txt | while read line                                              
     do                                                                              
     REPOSRC=$line                                                                   
     LOCALREPO=$line                                                                 
                                                                                     
     # We do it this way so that we can abstract if from just git later on           
     LOCALREPO_VC_DIR=$LOCALREPO/.git                                                
                                                                                     
     if [ ! -d $LOCALREPO_VC_DIR ]                                                   
    then                                                                            
       cd ~/xxxx                                                                
       gh repo clone $REPOSRC                                                       
       cd ~                                                                         
    else                                                                            
       cd ~                                                                         
       gh repo sync $REPOSRC -s $REPOSRC                                            
    fi                                                                              
    done                                                                            
    # End 

答案1

得分: 1

你正在寻找的排序键似乎是 sort=pushed

尝试运行 curl -s 'https://api.github.com/users/xxxx/repos?sort=pushed&per_page=100' | jq '.[].name' 进行验证。

英文:

The sort key
you're looking for seems to be sort=pushed.

Try curl -s 'https://api.github.com/users/xxxx/repos?sort=pushed&per_page=100' | jq '.[].name' to verify.

huangapple
  • 本文由 发表于 2023年1月6日 10:57:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/75026519.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定