support other repo

This commit is contained in:
Opportunity
2020-06-30 01:54:04 +08:00
Unverified
parent 2feaa3232f
commit 48f33e8789
66 changed files with 3280 additions and 1532 deletions
+13 -7
View File
@@ -2,15 +2,17 @@ import { exec } from '@actions/exec';
import * as io from '@actions/io';
import * as os from 'os';
import * as path from 'path';
import { Sha, RefDic } from './interfaces';
import { Sha, RefDic, Repo } from './interfaces';
function makeOpt(ref: Sha): { cwd: string } {
return { cwd: path.join(os.tmpdir(), `xmake-git-${ref}`) };
}
export async function lsRemote(): Promise<RefDic> {
const repoUrl = (repo: Repo): string => `https://github.com/${repo}.git`;
export async function lsRemote(repo: Repo): Promise<RefDic> {
let out = '';
await exec('git', ['ls-remote', 'https://github.com/xmake-io/xmake.git'], {
await exec('git', ['ls-remote', repoUrl(repo)], {
silent: true,
listeners: {
stdout: (d) => (out += d.toString()),
@@ -22,27 +24,31 @@ export async function lsRemote(): Promise<RefDic> {
if (ref && tag && tag.startsWith('refs/')) {
const tagPath = tag.split('/').splice(1);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let ldata = data as any;
let ldata = data as any; // eslint-disable-line @typescript-eslint/no-unsafe-assignment
for (let i = 0; i < tagPath.length - 1; i++) {
const seg = tagPath[i];
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
if (typeof ldata[seg] === 'object') {
ldata = ldata[seg];
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
ldata = ldata[seg]; // eslint-disable-line @typescript-eslint/no-unsafe-assignment
} else {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
ldata = ldata[seg] = {};
}
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
ldata[tagPath[tagPath.length - 1]] = ref;
}
});
return data;
}
export async function create(ref: Sha): Promise<string> {
export async function create(repo: Repo, ref: Sha): Promise<string> {
const opt = makeOpt(ref);
await io.rmRF(opt.cwd);
await io.mkdirP(opt.cwd);
await exec('git', ['init'], opt);
await exec('git', ['remote', 'add', 'origin', 'https://github.com/xmake-io/xmake.git'], opt);
await exec('git', ['remote', 'add', 'origin', repoUrl(repo)], opt);
await exec('git', ['fetch', 'origin', '+refs/pull/*:refs/remotes/origin/pull/*', '+refs/heads/*:refs/remotes/origin/*'], opt);
await exec('git', ['checkout', ref], opt);
await exec('git', ['submodule', 'update', '--init', '--recursive'], opt);