Merging two git repository into another with Github actions

I’m trying to merge 2 repository into a third one with the help of GitHub Actions. Note that the 3 repositories are private.

I tried to do it using secrets, but when I try to merge from the third repository, it cannot find any of the two other. Here is the workflows of the repositories:

Any of the first two:

name: Push to Third repo

on:
  push:
    branches:
      - main

jobs:
  trigger:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v2

      - name: Trigger the third repository
        run: |
          curl -X POST 
          -H "Authorization: token ${{ secrets.MY_SECRET_TOKEN }}" 
          -H "Accept: application/vnd.github.v3+json" 
          https://api.github.com/repos/MyOrganisation/ThirdRepo/dispatches 
          -d '{"event_type": "event_name_first"}'

And for the third one:

name: Merge Changes to Third

on:
  repository_dispatch:
    types: 
      - event_name_first
      - event_name_second

jobs:
  merge:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout repository
        uses: actions/checkout@v2

      - name: Configure git
        run: |
          git config --global user.name "github-actions"
          git config --global user.email "[email protected]"

      - name: Add remote repository
        run: |
          git remote add first https://github.com/MyOrganisation/first.git
          git remote add second https://github.com/MyOrganisation/second.git

      - name: Fetch latest changes from first or second
        run: |
          if [[ "${{ github.event.action }}" == "event_name_first" ]]; then
            git fetch first main
            git merge first/main --no-edit
          elif [[ "${{ github.event.action }}" == "event_name_second" ]]; then
            git fetch second main
            git merge second/main --no-edit
          fi

      - name: Push to main
        run: |
          git push origin main

An this is the error:

remote: Repository not found.
fatal: repository 'https://github.com/MyOrganisation/first.git/' not found
Error: Process completed with exit code 128.

I am sure of the names of every url. I suspect a missing permission on the secret token, even thought I gave it all repo and workflow rights.

Recognized by CI/CD Collective

New contributor

BigPocc is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

2

Your third workflow does not have permission to access any other repo but the repo where it is running. Token provided by GitHub Actions to each workflow is scoped to the repo where the workflow is defined.

You need to obtain Personal Access Token for each other repo. If you are a member of the first and second repos, you can use your own token. Otherwise you need a token from a member of both repos or two tokens from two different members.

The easiest way to apply these tokens with your implementation is the following:

git remote add first https://${{ secrets.TOKEN1 }}@github.com/MyOrganisation/first.git
git remote add second https://${{ secrets.TOKEN2 }}@github.com/MyOrganisation/second.git

These secrets must be defined in the third repo.

4

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật