Search code examples
gittypescriptgithubprobot

How to get names of all branches in repository?


For example, I have five branches in the current repository, and their names are: master, branch1, branch2, branch3, and branch4. Use the typescript language for probot build to get these names.

What I have tried:

import { Application } from 'probot' 
export = (app: Application) => {
  app.on(`*`, async context => {
    var branchName = context.github.repos.listBranches.name
    var branchName1 = context.github.repos.getBranch.name
    var branchName2 = context.payload.Status.branches.name
    console.log(branchName + "\n")
    // result: bound apiMethod
    console.log(branchName1 + "\n")
    // result: bound apiMethod
    console.log(branchName2 + "\n")
    // result: ERROR event: Cannot read property 'branches' of undefined
  })
}

Please explain about what does bound apiMethod mean here also.

Thank you!


Solution

  • const myRepoID = context.repo({number: context.payload.repository.id})
    await context.github.repos.listBranches(myRepoID)