File tree Expand file tree Collapse file tree 4 files changed +25
-13
lines changed Expand file tree Collapse file tree 4 files changed +25
-13
lines changed Original file line number Diff line number Diff line change 1+ import { LABELS , PROJECT_REPO_DETAILS } from "../../../constants.js" ;
12import app from "../octokit/app.js" ;
23import { decrypt } from "../utils/crypto.js" ;
3- import { buildStatsUrl } from "../utils/index.js" ;
4- import { PROJECT_REPO_DETAILS , LABELS } from "../../../constants.js" ;
4+ import { buildStatsUrl , getBranchNameFromRef } from "../utils/index.js" ;
55
66/**
77 * Get some jargons contribution stats for current user on the Jargons Editor
@@ -21,7 +21,7 @@ export default async function doContributionStats(astroGlobal) {
2121 const viewerLogin = me ?. login ;
2222
2323 const branchInfo = repoMainBranchRef
24- ? repoMainBranchRef . split ( "/" ) . slice ( 2 ) . join ( "/" )
24+ ? getBranchNameFromRef ( repoMainBranchRef )
2525 : "" ;
2626
2727 const baseQuery = `repo:${ repoFullname } is:pull-request type:pr author:${ viewerLogin } base:${ branchInfo } ` ;
Original file line number Diff line number Diff line change 11import { LABELS } from "../../constants.js" ;
2- import { getRepoParts } from "./utils/index.js" ;
3- import newWordPRTemp from "./templates/new-word-pr.md.js" ;
42import editWordPRTemp from "./templates/edit-word-pr.md.js" ;
3+ import newWordPRTemp from "./templates/new-word-pr.md.js" ;
4+ import { getBranchNameFromRef , getRepoParts } from "./utils/index.js" ;
55
66/**
77 * Submit word - create a Pull Request to add word to project repository
@@ -27,11 +27,10 @@ export async function submitWord(
2727 const { repoOwner : forkedRepoOwner } = getRepoParts (
2828 forkedRepoDetails . repoFullname ,
2929 ) ;
30- const baseBranch = repoMainBranchRef . split ( "/" ) . slice ( 2 ) . join ( "/" ) ;
31- const headBranch = forkedRepoDetails . repoChangeBranchRef
32- . split ( "/" )
33- . slice ( 2 )
34- . join ( "/" ) ;
30+ const baseBranch = getBranchNameFromRef ( repoMainBranchRef ) ;
31+ const headBranch = getBranchNameFromRef (
32+ forkedRepoDetails . repoChangeBranchRef ,
33+ ) ;
3534
3635 const title =
3736 action === "new"
Original file line number Diff line number Diff line change @@ -99,3 +99,12 @@ export function buildWordPathname(slug) {
9999export function buildWordSlug ( id ) {
100100 return id . split ( "." ) [ 0 ] ;
101101}
102+
103+ /**
104+ * Get branch name from branch ref
105+ * @param {string } branchRef
106+ * @returns {string }
107+ */
108+ export function getBranchNameFromRef ( branchRef ) {
109+ return branchRef . split ( "/" ) . slice ( 2 ) . join ( "/" ) ;
110+ }
Original file line number Diff line number Diff line change 11import wordFileTemplate from "./templates/word.md.js" ;
2- import { getRepoParts , normalizeAsUrl } from "./utils/index.js" ;
2+ import {
3+ getBranchNameFromRef ,
4+ getRepoParts ,
5+ normalizeAsUrl ,
6+ } from "./utils/index.js" ;
37
48/**
59 * Write and add a new word to user's forked dictionary
@@ -14,7 +18,7 @@ export async function writeNewWord(
1418) {
1519 const { repoFullname, repoChangeBranchRef } = forkedRepoDetails ;
1620 const { repoOwner, repoName } = getRepoParts ( repoFullname ) ;
17- const branch = repoChangeBranchRef . split ( "/" ) . slice ( 2 ) . join ( "/" ) ;
21+ const branch = getBranchNameFromRef ( repoChangeBranchRef ) ;
1822 const wordFileContent = writeWordFileContent ( title , content ) ;
1923
2024 try {
@@ -52,7 +56,7 @@ export async function updateExistingWord(
5256) {
5357 const { repoFullname, repoChangeBranchRef } = forkedRepoDetails ;
5458 const { repoOwner, repoName } = getRepoParts ( repoFullname ) ;
55- const branch = repoChangeBranchRef . split ( "/" ) . slice ( 2 ) . join ( "/" ) ;
59+ const branch = getBranchNameFromRef ( repoChangeBranchRef ) ;
5660 const wordFileContent = writeWordFileContent ( title , content ) ;
5761
5862 try {
You can’t perform that action at this time.
0 commit comments