get-last-major-for-master.js 826 B

1234567891011121314151617181920212223
  1. const { GitProcess } = require('dugite')
  2. const path = require('path')
  3. const semver = require('semver')
  4. const gitDir = path.resolve(__dirname, '..')
  5. async function getLastMajorForMaster () {
  6. let branchNames
  7. const result = await GitProcess.exec(['branch', '-a', '--remote', '--list', 'origin/[0-9]-[0-9]-x'], gitDir)
  8. if (result.exitCode === 0) {
  9. branchNames = result.stdout.trim().split('\n')
  10. const filtered = branchNames.map(b => b.replace('origin/', ''))
  11. return getNextReleaseBranch(filtered)
  12. } else {
  13. throw new Error('Release branches could not be fetched.')
  14. }
  15. }
  16. function getNextReleaseBranch (branches) {
  17. const converted = branches.map(b => b.replace(/-/g, '.').replace('x', '0'))
  18. return converted.reduce((v1, v2) => semver.gt(v1, v2) ? v1 : v2)
  19. }
  20. module.exports = { getLastMajorForMaster }