Skip to content

Commit

Permalink
Merge branch 'jb.pinalie/git-support' into alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
jybp committed Feb 15, 2021
2 parents 713a6ce + 9d252a2 commit 59abefa
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
uses: actions/setup-node@v1
with:
node-version: '12.x'
- run: yarn install
- run: yarn install --immutable
- run: yarn build
- run: yarn prettier-check
- run: yarn lint
Expand Down
Empty file.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
3 changes: 3 additions & 0 deletions src/commands/sourcemaps/__tests__/mjs/common.mjs.map
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"sources": ["webpack:///./src/commands/sourcemaps/__tests__/git.test.ts"]
}
57 changes: 57 additions & 0 deletions src/commands/sourcemaps/__tests__/upload.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os from 'os'

import {Cli} from 'clipanion/lib/advanced'
import {Payload} from '../interfaces'
import {UploadCommand} from '../upload'

describe('upload', () => {
Expand Down Expand Up @@ -81,6 +82,46 @@ describe('upload', () => {
expect(write.mock.calls[0][0]).toContain('DATADOG_API_KEY')
})
})

describe('addRepositoryDataToPayloads', () => {
test('repository url and commit still defined without payload', async () => {
const command = new UploadCommand()
const write = jest.fn()
command.context = {stdout: {write}} as any
const payloads = new Array<Payload>({
cliVersion: '0.0.1',
minifiedFilePath: 'src/commands/sourcemaps/__tests__/fixtures-empty/empty.min.js',
minifiedUrl: 'http://example/empty.min.js',
projectPath: '',
service: 'svc',
sourcemapPath: 'src/commands/sourcemaps/__tests__/fixtures-empty/empty.min.js.map',
version: '1.2.3',
})
await command['addRepositoryDataToPayloads'](payloads)
expect(payloads[0].gitRepositoryURL).toBeDefined()
expect(payloads[0].gitCommitSha).toHaveLength(40)
expect(payloads[0].gitRepositoryPayload).toBeUndefined()
})

test('should include payload', async () => {
const command = new UploadCommand()
const write = jest.fn()
command.context = {stdout: {write}} as any
const payloads = new Array<Payload>({
cliVersion: '0.0.1',
minifiedFilePath: 'src/commands/sourcemaps/__tests__/fixtures/common.min.js',
minifiedUrl: 'http://example/common.min.js',
projectPath: '',
service: 'svc',
sourcemapPath: 'src/commands/sourcemaps/__tests__/fixtures/common.min.js.map',
version: '1.2.3',
})
await command['addRepositoryDataToPayloads'](payloads)
expect(payloads[0].gitRepositoryURL).toBeDefined()
expect(payloads[0].gitCommitSha).toHaveLength(40)
expect(payloads[0].gitRepositoryPayload).toBeDefined()
})
})
})

describe('execute', () => {
Expand Down Expand Up @@ -154,6 +195,22 @@ describe('execute', () => {
version: '1234',
})
})

test('using the mjs extension', async () => {
const {context, code} = await runCLI('./src/commands/sourcemaps/__tests__/mjs')
const output = context.stdout.toString().split(os.EOL)
expect(code).toBe(0)
checkConsoleOutput(output, {
basePath: 'src/commands/sourcemaps/__tests__/mjs',
concurrency: 20,
jsFilesURLs: ['https://static.com/js/common.mjs'],
minifiedPathPrefix: 'https://static.com/js',
projectPath: '',
service: 'test-service',
sourcemapsPaths: ['src/commands/sourcemaps/__tests__/mjs/common.mjs.map'],
version: '1234',
})
})
})

const makeCli = () => {
Expand Down
10 changes: 8 additions & 2 deletions src/commands/sourcemaps/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,14 @@ export const uploadSourcemap = (request: (args: AxiosRequestConfig) => AxiosProm
form.append('minified_url', sourcemap.minifiedUrl)
form.append('project_path', sourcemap.projectPath)
form.append('type', 'js_sourcemap')
if (sourcemap.repository) {
form.append('repository', sourcemap.repository, {filename: 'repository', contentType: 'application/json'})
if (sourcemap.gitRepositoryPayload) {
form.append('repository', sourcemap.gitRepositoryPayload, {filename: 'repository', contentType: 'application/json'})
}
if (sourcemap.gitRepositoryURL) {
form.append('git_repository_url', sourcemap.gitRepositoryURL)
}
if (sourcemap.gitCommitSha) {
form.append('git_commit_sha', sourcemap.gitCommitSha)
}

return request({
Expand Down
4 changes: 3 additions & 1 deletion src/commands/sourcemaps/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import {Writable} from 'stream'

export interface Payload {
cliVersion: string
gitCommitSha?: string
gitRepositoryPayload?: string
gitRepositoryURL?: string
minifiedFilePath: string
minifiedUrl: string
overwrite?: boolean
projectPath: string
repository?: string
service: string
sourcemapPath: string
version: string
Expand Down
6 changes: 4 additions & 2 deletions src/commands/sourcemaps/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ export class UploadCommand extends Command {
}
await Promise.all(
payloads.map(async (payload) => {
payload.repository = this.getRepositoryPayload(repositoryData, payload.sourcemapPath)
payload.gitRepositoryPayload = this.getRepositoryPayload(repositoryData, payload.sourcemapPath)
payload.gitRepositoryURL = repositoryData.remote
payload.gitCommitSha = repositoryData.hash
})
)
}
Expand All @@ -134,7 +136,7 @@ export class UploadCommand extends Command {
// Looks for the sourcemaps and minified files on disk and returns
// the associated payloads.
private getMatchingSourcemapFiles = async (cliVersion: string): Promise<Payload[]> => {
const sourcemapFiles = glob.sync(buildPath(this.basePath!, '**/*.js.map'))
const sourcemapFiles = glob.sync(buildPath(this.basePath!, '**/*js.map'))

return Promise.all(
sourcemapFiles.map(async (sourcemapPath) => {
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4909,7 +4909,7 @@ signal-exit@^3.0.0, signal-exit@^3.0.2:
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"
integrity sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=

simple-git@^2.31.0:
[email protected]:
version "2.31.0"
resolved "https://registry.yarnpkg.com/simple-git/-/simple-git-2.31.0.tgz#3e5954c1e36c76fb382c08eaa2749a206db9f613"
integrity sha512-/+rmE7dYZMbRAfEmn8EUIOwlM2G7UdzpkC60KF86YAfXGnmGtsPrKsym0hKvLBdFLLW019C+aZld1+6iIVy5xA==
Expand Down

0 comments on commit 59abefa

Please sign in to comment.