@@ -15,6 +15,7 @@ export default class API {
15
15
this . branch = config . branch || "master" ;
16
16
this . repo = config . repo || "" ;
17
17
this . repoURL = `/repos/${ this . repo } ` ;
18
+ this . branchNameMaxLength = config . branchNameMaxLength || 40 ;
18
19
}
19
20
20
21
user ( ) {
@@ -85,8 +86,14 @@ export default class API {
85
86
} ) ;
86
87
}
87
88
89
+ truncateSlugForBranchName ( slug ) {
90
+ const slugMaxLength = this . branchNameMaxLength - CMS_BRANCH_PREFIX . length ;
91
+ return slug . substring ( 0 , slugMaxLength ) ;
92
+ }
93
+
88
94
generateBranchName ( basename ) {
89
- return `${ CMS_BRANCH_PREFIX } ${ basename } ` ;
95
+ const truncatedBasename = this . truncateSlugForBranchName ( basename ) ;
96
+ return `${ CMS_BRANCH_PREFIX } ${ truncatedBasename } ` ;
90
97
}
91
98
92
99
checkMetadataRef ( ) {
@@ -111,7 +118,10 @@ export default class API {
111
118
} ) ;
112
119
}
113
120
114
- storeMetadata ( key , data ) {
121
+ storeMetadata ( contentKey , data ) {
122
+ // metadata filenames need to match branch names - see
123
+ // unpublishedEntries in src/backends/github/implementation.js
124
+ const key = this . truncateSlugForBranchName ( contentKey ) ;
115
125
return this . checkMetadataRef ( )
116
126
. then ( ( branchData ) => {
117
127
const fileTree = {
@@ -135,7 +145,10 @@ export default class API {
135
145
} ) ;
136
146
}
137
147
138
- retrieveMetadata ( key ) {
148
+ retrieveMetadata ( contentKey ) {
149
+ // metadata filenames need to match branch names - see
150
+ // unpublishedEntries in src/backends/github/implementation.js
151
+ const key = this . truncateSlugForBranchName ( contentKey ) ;
139
152
const cache = LocalForage . getItem ( `gh.meta.${ key } ` ) ;
140
153
return cache . then ( ( cached ) => {
141
154
if ( cached && cached . expires > Date . now ( ) ) { return cached . data ; }
0 commit comments