-
Notifications
You must be signed in to change notification settings - Fork 320
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9064 from quarto-dev/feature/publish-hugging-face
Feature/publish hugging face
- Loading branch information
Showing
8 changed files
with
344 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
* errors.ts | ||
* | ||
* Copyright (C) 2020-2024 Posit Software, PBC | ||
*/ | ||
|
||
export const throwUnableToPublish = (reason: string, provider: string) => { | ||
throw new Error( | ||
`Unable to publish to ${provider} (${reason})`, | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* git.ts | ||
* | ||
* Copyright (C) 2020-2024 Posit Software, PBC | ||
*/ | ||
|
||
import { websiteBaseurl } from "../../project/types/website/website-config.ts"; | ||
import { gitHubContext } from "../../core/github.ts"; | ||
import { ProjectContext } from "../../project/types.ts"; | ||
import { dirname } from "../../deno_ral/path.ts"; | ||
import { AccountToken, AccountTokenType } from "../provider-types.ts"; | ||
import { PublishOptions } from "../types.ts"; | ||
import { GitHubContext } from "../../core/github-types.ts"; | ||
import { throwUnableToPublish } from "./errors.ts"; | ||
|
||
export async function gitHubContextForPublish(input: string | ProjectContext) { | ||
// Create the base context | ||
const dir = typeof input === "string" ? dirname(input) : input.dir; | ||
const context = await gitHubContext(dir); | ||
|
||
// always prefer configured website URL | ||
if (typeof input !== "string") { | ||
const configSiteUrl = websiteBaseurl(input?.config); | ||
if (configSiteUrl) { | ||
context.siteUrl = configSiteUrl; | ||
} | ||
} | ||
return context; | ||
} | ||
|
||
export function anonymousAccount(): AccountToken { | ||
return { | ||
type: AccountTokenType.Anonymous, | ||
name: "anonymous", | ||
server: null, | ||
token: "anonymous", | ||
}; | ||
} | ||
|
||
export function verifyContext( | ||
ghContext: GitHubContext, | ||
provider: string, | ||
) { | ||
if (!ghContext.git) { | ||
throwUnableToPublish( | ||
"git does not appear to be installed on this system", | ||
provider, | ||
); | ||
} | ||
|
||
// validate we are in a git repo | ||
if (!ghContext.repo) { | ||
throwUnableToPublish( | ||
"the target directory is not a git repository", | ||
provider, | ||
); | ||
} | ||
|
||
// validate that we have an origin | ||
if (!ghContext.originUrl) { | ||
throwUnableToPublish( | ||
"the git repository does not have a remote origin", | ||
provider, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.