Programmatic API
May 3, 2026 · View on GitHub
The backport package can be imported as a Node module for use in automation scripts. See the Backport GitHub Action for a real-world example.
backportRun(options, processArgs, exitCodeOnFailure)
Backport one or more commits programmatically. Commits can be selected via pullNumber or sha.
Arguments:
optionsobject — accepts all configuration optionsprocessArgsstring[] — forward CLI arguments from the calling process (e.g.process.argv.slice(2))exitCodeOnFailureboolean — iftrue, sets a non-zero exit code on failure. Default:true
Example:
import { backportRun } from 'backport';
const result = await backportRun({
options: {
githubToken: 'ghp_very_secret',
repoName: 'kibana',
repoOwner: 'elastic',
pullNumber: 121633,
interactive: false,
},
});
getCommits(options)
Retrieve information about commits and whether they have been backported. Useful for building dashboards or CI status checks.
Arguments:
githubTokenstring (Required) — GitHub access tokenrepoNamestring (Required) — Name of repositoryrepoOwnerstring (Required) — Owner of repository (organisation or username)authorstring — Filter commits by GitHub usernamepullNumbernumber — Filter commits by pull request numbershastring — Filter commits by commit shasourceBranchstring — Branch to list commits from. Defaults to the repository's default branch
Example:
import { getCommits } from 'backport';
const commits = await getCommits({
githubToken: 'ghp_very_secret',
repoName: 'kibana',
repoOwner: 'elastic',
pullNumber: 121633,
});
/*
[{
sourceCommit: {
committedDate: '2021-12-20T14:20:16Z',
sha: 'd421ddcf6157150596581c7885afa3690cec6339',
message: '[APM] Add note about synthtrace to APM docs (#121633)',
},
sourcePullRequest: {
number: 121633,
url: 'https://github.com/elastic/kibana/pull/121633',
mergeCommit: {
sha: 'd421ddcf6157150596581c7885afa3690cec6339',
message: '[APM] Add note about synthtrace to APM docs (#121633)',
}
},
sourceBranch: 'main',
targetPullRequestStates: [
{
url: 'https://github.com/elastic/kibana/pull/121643',
number: 121643,
branch: '8.0',
state: 'MERGED'
}
]
}]
*/