Repository: teleporthq/teleport-code-generators (ts)

Issue:
Rename default branch for github publisher
When a project is created with the publisher it has the default branch `main`. We need to rename the default in the publisher from `master` to `main` and also to rename the variables / functions that have `master` in the name, for consistency.

Pull request description:
fix(github-publisher): changing default branch to main instead of master
fixes #495 

Patch:
diff --git a/packages/teleport-publisher-github/src/index.ts b/packages/teleport-publisher-github/src/index.ts
index 48ed4cdd..f6220600 100644
--- a/packages/teleport-publisher-github/src/index.ts
+++ b/packages/teleport-publisher-github/src/index.ts
@@ -17,7 +17,7 @@ export const createGithubPublisher: PublisherFactory<GithubFactoryParams, Github
   params: GithubFactoryParams = {}
 ): GithubPublisher => {
   const { authMeta } = params
-  let { project, repository, repositoryOwner, masterBranch, commitBranch, commitMessage } = params
+  let { project, repository, repositoryOwner, mainBranch, commitBranch, commitMessage } = params
 
   const getProject = () => project
   const setProject = (projectToSet: GeneratedFolder) => {
@@ -29,9 +29,9 @@ export const createGithubPublisher: PublisherFactory<GithubFactoryParams, Github
     repository = repo
   }
 
-  const getMasterBranchName = () => masterBranch
-  const setMasterBranchName = (branch: string) => {
-    masterBranch = branch
+  const getMainBranchName = () => mainBranch
+  const setMainBranchName = (branch: string) => {
+    mainBranch = branch
   }
 
   const getCommitBranchName = () => commitBranch
@@ -67,15 +67,15 @@ export const createGithubPublisher: PublisherFactory<GithubFactoryParams, Github
 
     const repoOwner = findRepositoryOwner(auth, options)
 
-    const masterBranchName = options.masterBranch || masterBranch
-    const master = masterBranchName ? masterBranch : 'master'
+    const mainBranchName = options.mainBranch || mainBranch
+    const main = mainBranchName ? mainBranch : 'main'
     const commitBranchName = options.commitBranch || commitBranch
     const commitMsg = options.commitMessage || commitMessage
 
     const githubPublishMeta: GithubPublishMeta = {
       authMeta: auth,
-      masterBranch: master,
-      commitBranch: commitBranchName ? commitBranchName : master,
+      mainBranch: main,
+      commitBranch: commitBranchName ? commitBranchName : main,
       commitMessage: commitMsg,
       repository: repo,
       repositoryOwner: repoOwner,
@@ -112,8 +112,8 @@ export const createGithubPublisher: PublisherFactory<GithubFactoryParams, Github
     setProject,
     getRepository,
     setRepository,
-    getMasterBranchName,
-    setMasterBranchName,
+    getMainBranchName,
+    setMainBranchName,
     getCommitBranchName,
     setCommitBranchName,
     getCommitMessage,
diff --git a/packages/teleport-publisher-github/src/types.ts b/packages/teleport-publisher-github/src/types.ts
index 6a2aa04e..82a503da 100644
--- a/packages/teleport-publisher-github/src/types.ts
+++ b/packages/teleport-publisher-github/src/types.ts
@@ -10,7 +10,7 @@ export interface GithubFactoryParams extends PublisherFactoryParams {
   authMeta?: ServiceAuth
   repositoryOwner?: string
   repository?: string
-  masterBranch?: string
+  mainBranch?: string
   commitBranch?: string
   commitMessage?: string
 }
@@ -18,8 +18,8 @@ export interface GithubFactoryParams extends PublisherFactoryParams {
 export interface GithubPublisher extends Publisher<GithubFactoryParams, string> {
   getRepository: () => string
   setRepository: (repo: string) => void
-  getMasterBranchName: () => string
-  setMasterBranchName: (branch: string) => void
+  getMainBranchName: () => string
+  setMainBranchName: (branch: string) => void
   getCommitBranchName: () => string
   setCommitBranchName: (branch: string) => void
   getCommitMessage: () => string
@@ -32,7 +32,7 @@ export interface GithubPublishMeta {
   authMeta: ServiceAuth
   repository: string
   repositoryOwner: string
-  masterBranch?: string
+  mainBranch?: string
   commitBranch?: string
   commitMessage?: string
 }
diff --git a/packages/teleport-publisher-github/src/utils.ts b/packages/teleport-publisher-github/src/utils.ts
index 5d2a334e..d6ee4a9a 100644
--- a/packages/teleport-publisher-github/src/utils.ts
+++ b/packages/teleport-publisher-github/src/utils.ts
@@ -42,12 +42,12 @@ export const generateProjectFiles = (folderInfo: ProjectFolderInfo): GithubFile[
 }
 
 export const publishToGithub = async (files: GithubFile[], meta: GithubPublishMeta) => {
-  const { authMeta, masterBranch, commitBranch, commitMessage, repository, repositoryOwner } = meta
+  const { authMeta, mainBranch, commitBranch, commitMessage, repository, repositoryOwner } = meta
 
   const repositoryIdentity: RepositoryIdentity = {
     username: repositoryOwner,
     repo: repository,
-    ref: masterBranch,
+    ref: mainBranch,
   }
 
   const gitCommitMeta: GithubCommitMeta = {


Test patch:
diff --git a/packages/teleport-publisher-github/__tests__/index.ts b/packages/teleport-publisher-github/__tests__/index.ts
index 4a0f325c..3d9bc92e 100644
--- a/packages/teleport-publisher-github/__tests__/index.ts
+++ b/packages/teleport-publisher-github/__tests__/index.ts
@@ -1,21 +1,23 @@
 import { createGithubPublisher } from '../src'
 
-import project from './project-files.json'
+import projectJSON from './project-files.json'
 import githubFiles from './github-files-content.json'
 import { generateProjectFiles } from '../src/utils'
+import { GeneratedFolder } from '@teleporthq/teleport-types'
 
+const project = projectJSON as GeneratedFolder
 describe('teleport publisher github', () => {
   it('creates a new instance of github publisher', () => {
     const publisher = createGithubPublisher()
     expect(publisher.getCommitMessage).toBeDefined()
-    expect(publisher.getMasterBranchName).toBeDefined()
+    expect(publisher.getMainBranchName).toBeDefined()
     expect(publisher.getCommitBranchName).toBeDefined()
     expect(publisher.getProject).toBeDefined()
     expect(publisher.getRepository).toBeDefined()
     expect(publisher.getRepositoryOwner).toBeDefined()
 
     expect(publisher.setCommitMessage).toBeDefined()
-    expect(publisher.setMasterBranchName).toBeDefined()
+    expect(publisher.setMainBranchName).toBeDefined()
     expect(publisher.setCommitBranchName).toBeDefined()
     expect(publisher.setProject).toBeDefined()
     expect(publisher.setRepository).toBeDefined()
@@ -44,9 +46,9 @@ describe('teleport publisher github', () => {
   it('should set master branch name', () => {
     const BRANCH = 'master'
     const publisher = createGithubPublisher()
-    publisher.setMasterBranchName(BRANCH)
+    publisher.setMainBranchName(BRANCH)
 
-    const publisherMasterBranch = JSON.stringify(publisher.getMasterBranchName())
+    const publisherMasterBranch = JSON.stringify(publisher.getMainBranchName())
     expect(publisherMasterBranch).toBe(JSON.stringify(BRANCH))
   })
 
@@ -100,7 +102,7 @@ describe('teleport publisher github', () => {
   })
 
   it('should generate github project files from generated folder', () => {
-    const files = generateProjectFiles({ folder: project, ignoreFolder: true })
+    const files = generateProjectFiles({ folder: { ...project }, ignoreFolder: true })
     expect(JSON.stringify(files)).toBe(JSON.stringify(githubFiles))
   })
 })