-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show warnings about unmerged parent pull requests (#18)
* Show dependency warning under PR body * add feature to readme
- Loading branch information
Showing
7 changed files
with
100 additions
and
7 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,68 @@ | ||
import { h } from "dom-chef"; | ||
import { getPullRequests } from "../api"; | ||
import { | ||
createIdForPullRequest, | ||
getBasePullRequestWithStackerInfo | ||
} from "../lib/base"; | ||
import { IStackerContext } from "../lib/context"; | ||
import { getBodyTextarea } from "../lib/dom"; | ||
import { getLocation, getPullRequestURL } from "../lib/location"; | ||
import { getStackerInfo } from "../lib/prInfo"; | ||
|
||
function getTextareaStackerInfo() { | ||
const $textarea = getBodyTextarea(); | ||
return $textarea && getStackerInfo($textarea.value); | ||
} | ||
const WARNING_ID = "stacker-merge-warning"; | ||
export default async function initialize(context: IStackerContext) { | ||
const $comment = document.querySelector(".comment-body"); | ||
|
||
const location = getLocation(context.location); | ||
|
||
const pullRequests = await getPullRequests(context.accessToken)( | ||
location.ownerLogin, | ||
location.repoName | ||
); | ||
|
||
const stackerInfo = getTextareaStackerInfo(); | ||
const basePR = | ||
stackerInfo && getBasePullRequestWithStackerInfo(stackerInfo, pullRequests); | ||
|
||
// Handle existing warning | ||
const $warning = document.getElementById(WARNING_ID); | ||
if ($warning) { | ||
if (!basePR) { | ||
// Clear existing warning | ||
$warning.remove(); | ||
return; | ||
} | ||
|
||
if ( | ||
createIdForPullRequest(basePR) === | ||
$warning.getAttribute("data-stacker-pr") | ||
) { | ||
// Keep existing warning | ||
return; | ||
} | ||
} | ||
|
||
if (!(stackerInfo && $comment && $comment.firstElementChild)) { | ||
return; | ||
} | ||
|
||
if (!basePR) { | ||
return; | ||
} | ||
|
||
$comment.insertBefore( | ||
<p id={WARNING_ID} data-stacker-pr={createIdForPullRequest(basePR)}> | ||
⚠️ This pull request depends on{" "} | ||
<strong> | ||
<a href={getPullRequestURL(basePR)} target="_blank"> | ||
#{basePR.number} {basePR.title} | ||
</a> | ||
</strong>. Consider merging it before merging this one. | ||
</p>, | ||
$comment.firstElementChild.nextSibling | ||
); | ||
} |
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 @@ | ||
export function getBodyTextarea(): HTMLTextAreaElement | null { | ||
return document.querySelector( | ||
'textarea[name="pull_request[body]"]' | ||
) as HTMLTextAreaElement | null; | ||
} | ||
|
||
export function getBodyTextareaValue(): string | null { | ||
const $textarea = getBodyTextarea(); | ||
|
||
return $textarea && $textarea.value; | ||
} |
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