Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/src/publish/common/git.ts
6458 views
1
/*
2
* git.ts
3
*
4
* Copyright (C) 2020-2024 Posit Software, PBC
5
*/
6
7
import { websiteBaseurl } from "../../project/types/website/website-config.ts";
8
import { gitHubContext } from "../../core/github.ts";
9
import { ProjectContext } from "../../project/types.ts";
10
import { dirname } from "../../deno_ral/path.ts";
11
import { AccountToken, AccountTokenType } from "../provider-types.ts";
12
import { PublishOptions } from "../types.ts";
13
import { GitHubContext } from "../../core/github-types.ts";
14
import { throwUnableToPublish } from "./errors.ts";
15
16
export async function gitHubContextForPublish(input: string | ProjectContext) {
17
// Create the base context
18
const dir = typeof input === "string" ? dirname(input) : input.dir;
19
const context = await gitHubContext(dir);
20
21
// always prefer configured website URL
22
if (typeof input !== "string") {
23
const configSiteUrl = websiteBaseurl(input?.config);
24
if (configSiteUrl) {
25
context.siteUrl = configSiteUrl;
26
}
27
}
28
return context;
29
}
30
31
export function anonymousAccount(): AccountToken {
32
return {
33
type: AccountTokenType.Anonymous,
34
name: "anonymous",
35
server: null,
36
token: "anonymous",
37
};
38
}
39
40
export function verifyContext(
41
ghContext: GitHubContext,
42
provider: string,
43
) {
44
if (!ghContext.git) {
45
throwUnableToPublish(
46
"git does not appear to be installed on this system",
47
provider,
48
);
49
}
50
51
// validate we are in a git repo
52
if (!ghContext.repo) {
53
throwUnableToPublish(
54
"the target directory is not a git repository",
55
provider,
56
);
57
}
58
59
// validate that we have an origin
60
if (!ghContext.originUrl) {
61
throwUnableToPublish(
62
"the git repository does not have a remote origin",
63
provider,
64
);
65
}
66
}
67
68