Skip to content

Commit b821d89

Browse files
committed
Include repo object in templating context
1 parent 8b92be3 commit b821d89

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

src/config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ const parseRepoName = (fullRepo) => {
161161
const branch = fullRepo.split('@')[1] || 'default'
162162

163163
return {
164+
url: `https://${ host }/${ user }/${ name }`,
164165
fullName: `${ host }/${ user }/${ name }`,
165166
uniqueName: `${ host }/${ user }/${ name }@${ branch }`,
166167
host,
@@ -248,4 +249,4 @@ export async function parseConfig() {
248249
return Object.values(result)
249250
}
250251

251-
export default context
252+
export default context

src/helpers.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,19 @@ export async function pathIsDirectory(path) {
6969
return stat.isDirectory()
7070
}
7171

72-
export async function write(src, dest, context) {
72+
export async function write(src, dest, context, item) {
7373
if (typeof context !== 'object') {
7474
context = {}
7575
}
76+
77+
// include current repo constants (e.g., host, user, name, branch, etc.)
78+
context.repo = item.repo
79+
7680
const content = nunjucks.render(src, context)
7781
await fs.outputFile(dest, content)
7882
}
7983

80-
export async function copy(src, dest, isDirectory, file) {
84+
export async function copy(src, dest, isDirectory, file, item) {
8185
const deleteOrphaned = isDirectory && file.deleteOrphaned
8286
const exclude = file.exclude
8387

@@ -121,12 +125,12 @@ export async function copy(src, dest, isDirectory, file) {
121125

122126
const srcPath = path.join(src, srcFile)
123127
const destPath = path.join(dest, srcFile)
124-
await write(srcPath, destPath, file.template)
128+
await write(srcPath, destPath, file.template, item)
125129
}
126130
} else {
127131
core.debug(`Render file ${ src } to ${ dest }`)
128132

129-
await write(src, dest, file.template)
133+
await write(src, dest, file.template, item)
130134
}
131135
} else {
132136
core.debug(`Copy ${ src } to ${ dest }`)
@@ -166,4 +170,4 @@ export async function remove(src) {
166170

167171
export function arrayEquals(array1, array2) {
168172
return Array.isArray(array1) && Array.isArray(array2) && array1.length === array2.length && array1.every((value, i) => value === array2[i])
169-
}
173+
}

src/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ async function run() {
3333

3434
await forEach(repos, async (item) => {
3535
core.info(`Repository Info`)
36-
core.info(`Slug : ${ item.repo.name }`)
37-
core.info(`Owner : ${ item.repo.user }`)
38-
core.info(`Https Url : https://${ item.repo.fullName }`)
39-
core.info(`Branch : ${ item.repo.branch }`)
36+
core.info(`Slug : ${ item.repo.name }`)
37+
core.info(`Owner : ${ item.repo.user }`)
38+
core.info(`Url : ${ item.repo.url }`)
39+
core.info(`Branch : ${ item.repo.branch }`)
4040
core.info(' ')
4141
try {
4242

@@ -74,7 +74,7 @@ async function run() {
7474

7575
if (isDirectory) core.info(`Source is directory`)
7676

77-
await copy(source, dest, isDirectory, file)
77+
await copy(source, dest, isDirectory, file, item)
7878

7979
await git.add(file.dest)
8080

@@ -220,4 +220,4 @@ run()
220220
.catch((err) => {
221221
core.setFailed(err.message)
222222
core.debug(err)
223-
})
223+
})

0 commit comments

Comments
 (0)