Skip to content

Commit

Permalink
Merge pull request #479 from loremattei/fetch-rules-from-dev-branch
Browse files Browse the repository at this point in the history
Fetch rules from dev branch
  • Loading branch information
orta authored Aug 19, 2021
2 parents 081886f + 0d0e5bc commit 4c71098
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 9 deletions.
2 changes: 1 addition & 1 deletion api/source/danger/danger_run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export interface RepresentationForURL {
/** Takes a DangerfileReferenceString and lets you know where to find it globally */
export const dangerRepresentationForPath = (value: DangerfileReferenceString): RepresentationForURL => {
let afterAt = value.includes("@") ? value.split("@")[1] : value
afterAt = afterAt.startsWith('/') ? afterAt.substring(1) : afterAt;
afterAt = afterAt.startsWith("/") ? afterAt.substring(1) : afterAt
return {
branch: value.includes("#") ? value.split("#")[1] : "master",
dangerfilePath: afterAt.split("#")[0],
Expand Down
7 changes: 4 additions & 3 deletions api/source/db/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,11 @@ export const jsonDatabase = (dangerFilePath: DangerfileReferenceString): Databas
getSchedulableInstallationsWithKey: () => Promise.resolve([org]),

setup: async () => {
const repo = dangerFilePath.split("@")[0]
const path = dangerFilePath.split("@")[1]
const ref = dangerFilePath.includes("#") ? dangerFilePath.split("#")[1] : null
const repo = dangerFilePath.split("#")[0].split("@")[0]
const path = dangerFilePath.split("#")[0].split("@")[1]

const file = await getGitHubFileContentsWithoutToken(repo, path)
const file = await getGitHubFileContentsWithoutToken(repo, path, ref)

if (file === "") {
throwNoJSONFileFound(dangerFilePath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,36 @@
},
"installation": {
"id": 23511
},
"api": {
"log": {},
"activity": {},
"apps": {},
"checks": {},
"codesOfConduct": {},
"emojis": {},
"gists": {},
"git": {},
"gitignore": {},
"interactions": {},
"issues": {},
"licenses": {},
"markdown": {},
"meta": {},
"migrations": {},
"oauthAuthorizations": {},
"orgs": {},
"projects": {},
"pulls": {},
"rateLimit": {},
"reactions": {},
"repos": {},
"search": {},
"teams": {},
"users": {},
"gitdata": {},
"authorization": {},
"pullRequests": {}
}
},
"settings": {
Expand Down
2 changes: 1 addition & 1 deletion api/source/github/events/handlers/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const runEventRun = async (
const results = await runDangerForInstallation(
eventName,
contents,
runs.map(r => r.referenceString),
runs.map(r => r.referenceString.split("#")[0]),
githubAPI,
RunType.import,
installationSettings,
Expand Down
4 changes: 2 additions & 2 deletions api/source/github/events/handlers/pr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const runPRRun = async (

const headDangerfile = await getGitHubFileContents(token, repoForDangerfile, run.dangerfilePath, run.branch)
contents.push(headDangerfile)
dangerfileReferences.push(run.referenceString)
dangerfileReferences.push(run.referenceString.split("#")[0])
}

// Everything is :+1:
Expand Down Expand Up @@ -109,7 +109,7 @@ const validateRuns = async (

for (const run of runs) {
const neededDangerfileIsLocalRepo = !run.repoSlug
const branch = neededDangerfileIsLocalRepo ? dangerfileBranchForPR : null
const branch = neededDangerfileIsLocalRepo ? dangerfileBranchForPR : run.branch

// Either it's dictated in the run as an external repo, or we use the most natural repo
const repoForDangerfileRun = run.repoSlug || dangerfileRepoForPR
Expand Down
4 changes: 2 additions & 2 deletions api/source/github/lib/github_helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ export async function getGitHubFileContents(
* in the environment it will build the appropriate auth.
* Returns either the contents or an empty string.
*/
export async function getGitHubFileContentsWithoutToken(repo: string, path: string) {
export async function getGitHubFileContentsWithoutToken(repo: string, path: string, ref: string | null) {
// Try see if we can pull it without an access token
const file = await getGitHubFileContents(null, repo, path, null, false)
const file = await getGitHubFileContents(null, repo, path, ref, false)
if (file !== "") {
return file
}
Expand Down

0 comments on commit 4c71098

Please sign in to comment.