Skip to content

Commit

Permalink
Extract files from container
Browse files Browse the repository at this point in the history
  • Loading branch information
Nish Sinha committed Jul 20, 2021
1 parent 183db6e commit eb67794
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions src/updater.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as core from '@actions/core'
import * as Docker from 'dockerode'
import path from 'path'
import fs from 'fs'
import {Credential, JobDetails, DependabotAPI} from './dependabot-api'
import {Readable} from 'stream'
import {pack} from 'tar-stream'
Expand All @@ -12,6 +13,8 @@ const JOB_OUTPUT_PATH = '/home/dependabot/dependabot-updater/output/output.json'
const DEFAULT_UPDATER_IMAGE =
'docker.pkg.github.com/dependabot/dependabot-updater:latest'

const decode = (str: string):string => Buffer.from(str, 'base64').toString('binary');

export class Updater {
constructor(
private readonly docker: Docker,
Expand Down Expand Up @@ -67,6 +70,12 @@ export class Updater {
}
}

private decodeBase64Content(file: DependencyFile) {
const fileCopy = JSON.parse(JSON.stringify(file))
fileCopy.content = decode(fileCopy.content)
return fileCopy
}

private async runFileFetcher(
details: JobDetails,
credentials: Credential[]
Expand All @@ -78,12 +87,16 @@ export class Updater {
})
await this.runContainer(container)

// TODO: extract files from container
return {
base_commit_sha: '',
dependency_files: [],
base64_dependency_files: []
const fileFetcherSync = fs.readFileSync(path.join(__dirname, "../output/output.json")).toString();
const fileFetcherOutput = JSON.parse(fileFetcherSync)

const fetchedFiles: FetchedFiles = {
base_commit_sha: fileFetcherOutput.base_commit_sha,
base64_dependency_files: fileFetcherOutput.base64_dependency_files,
dependency_files: fileFetcherOutput.base64_dependency_files.map(this.decodeBase64Content)
}

return fetchedFiles
}

private async runFileUpdater(
Expand Down Expand Up @@ -161,6 +174,17 @@ type FetchedFiles = {
base64_dependency_files: any[]
}

type DependencyFile = {
name: string
content: any
directory: string
type: string
support_file: boolean
content_encoding: string
deleted: boolean
operation: string
}

type FileUpdaterInput = FetchedFiles & {
job: JobDetails
}

0 comments on commit eb67794

Please sign in to comment.