Skip to content

Commit

Permalink
Merge branch 'main' into feature/add-AdjustStandardEnvironmentNameCas…
Browse files Browse the repository at this point in the history
…ing-dotnetcore-option
  • Loading branch information
bruno-garcia committed Jun 17, 2021
2 parents 59d4a59 + e3bde53 commit 53323f0
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 87 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## Unreleased

### Fixes

- Handle error thrown while trying to get `BootTime` on PS4 with IL2CPP ([#1062](https://github.com/getsentry/sentry-dotnet/pull/1062))


### Changes

- Use SentryId for ISession.Id ([#1052](https://github.com/getsentry/sentry-dotnet/pull/1052))
Expand Down
129 changes: 75 additions & 54 deletions dangerfile.js
Original file line number Diff line number Diff line change
@@ -1,76 +1,97 @@
async function checkDocs() {
if (danger.github.pr.title.startsWith("feat:")) {
message(
'Do not forget to update <a href="https://github.com/getsentry/sentry-docs">Sentry-docs</a> with your feature once the pull request gets approved.'
);
}
}
const PR_LINK = `([#${danger.github.pr.number}](${danger.github.pr.html_url}))`;

async function checkChangelog() {
const changelogFile = "CHANGELOG.md";
const CHANGELOG_SUMMARY_TITLE = `Instructions and example for changelog`;
const CHANGELOG_BODY = `Please add an entry to \`CHANGELOG.md\` to the "Unreleased" section. Make sure the entry includes this PR's number.
// Check if skipped
const skipChangelog = danger.github && (danger.github.pr.body + "").includes("#skip-changelog");
if (skipChangelog) {
return;
}
Example:`;

// Check if current PR has an entry in changelog
const changelogContents = await danger.github.utils.fileContents(changelogFile);
const CHANGELOG_END_BODY = `If none of the above apply, you can opt out of this check by adding \`#skip-changelog\` to the PR description.`;

const hasChangelogEntry = RegExp(`#${danger.github.pr.number}\\b`).test(changelogContents);
if (hasChangelogEntry) {
return;
}
function getCleanTitleWithPrLink() {
const title = danger.github.pr.title;
return title.split(": ").slice(-1)[0].trim().replace(/\.+$/, "") + PR_LINK;
}

// Short-circuit if lacking permissions
const hasCommentPermission = danger.github.pr.head.repo.git_url == danger.github.pr.base.repo.git_url;
if (!hasCommentPermission) {
console.log("Please consider adding a changelog entry for the next release.");
process.exitCode = 1;
return;
}
function getChangelogDetailsHtml() {
return `
### ${CHANGELOG_SUMMARY_TITLE}
// Report missing changelog entry
fail(
"Please consider adding a changelog entry for the next release.",
changelogFile
);
${CHANGELOG_BODY}
const prTitleFormatted = danger.github.pr.title
.split(": ")
.slice(-1)[0]
.trim()
.replace(/\.+$/, "");
\`\`\`markdown
- ${getCleanTitleWithPrLink()}
\`\`\`
markdown(
`
### Instructions and example for changelog
${CHANGELOG_END_BODY}
`;
}

Please add an entry to \`CHANGELOG.md\` to the "Unreleased" section. Make sure the entry includes this PR's number.
function getChangelogDetailsTxt() {
return (
CHANGELOG_SUMMARY_TITLE +
"\n" +
CHANGELOG_BODY +
"\n" +
getCleanTitleWithPrLink() +
"\n" +
CHANGELOG_END_BODY
);
}

Example:
function HasPermissionToComment() {
return (
danger.github.pr.head.repo.git_url == danger.github.pr.base.repo.git_url
);
}

\`\`\`markdown
## Unreleased
async function containsChangelog(path) {
const contents = await danger.github.utils.fileContents(path);
return contents.includes(PR_LINK);
}

- ${prTitleFormatted} ([#${danger.github.pr.number}](${danger.github.pr.html_url}))
\`\`\`
async function checkChangelog() {
const skipChangelog =
danger.github && (danger.github.pr.body + "").includes("#skip-changelog");
if (skipChangelog) {
return;
}

const hasChangelog = await containsChangelog("CHANGELOG.md");

if (!hasChangelog) {
if (HasPermissionToComment()) {
fail("Please consider adding a changelog entry for the next release.");
markdown(getChangelogDetailsHtml());
} else {
//Fallback
console.log(
"Please consider adding a changelog entry for the next release."
);
console.log(getChangelogDetailsTxt());
process.exitCode = 1;
}
}
}

If none of the above apply, you can opt out of this check by adding \`#skip-changelog\` to the PR description.`.trim()
async function checkIfFeature() {
const title = danger.github.pr.title;
if (title.startsWith("feat:") && HasPermissionToComment()) {
message(
'Do not forget to update <a href="https://github.com/getsentry/sentry-docs">Sentry-docs</a> with your feature once the pull request gets approved.'
);
}
}

async function checkAll() {
// See: https://spectrum.chat/danger/javascript/support-for-github-draft-prs~82948576-ce84-40e7-a043-7675e5bf5690
const isDraft = danger.github.pr.mergeable_state === "draft";
// See: https://spectrum.chat/danger/javascript/support-for-github-draft-prs~82948576-ce84-40e7-a043-7675e5bf5690
const isDraft = danger.github.pr.mergeable_state === "draft";

if (isDraft) {
return;
}
if (isDraft) {
return;
}

await checkDocs();
await checkChangelog();
await checkIfFeature();
await checkChangelog();
}

schedule(checkAll);
85 changes: 57 additions & 28 deletions src/Sentry/Extensibility/DiagnosticLoggerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static class DiagnosticLoggerExtensions
this IDiagnosticLogger logger,
string message,
TArg arg)
=> logger.LogIfEnabled(SentryLevel.Debug, message, arg);
=> logger.LogIfEnabled(SentryLevel.Debug, null, message, arg);

/// <summary>
/// Log a debug message.
Expand All @@ -27,23 +27,23 @@ public static class DiagnosticLoggerExtensions
string message,
TArg arg,
TArg2 arg2)
=> logger.LogIfEnabled(SentryLevel.Debug, message, arg, arg2);
=> logger.LogIfEnabled(SentryLevel.Debug, null, message, arg, arg2);

/// <summary>
/// Log a debug message.
/// </summary>
public static void LogDebug(
this IDiagnosticLogger logger,
string message)
=> logger.LogIfEnabled(SentryLevel.Debug, message);
=> logger.LogIfEnabled(SentryLevel.Debug, null, message);

/// <summary>
/// Log a info message.
/// </summary>
public static void LogInfo(
this IDiagnosticLogger logger,
string message)
=> logger.LogIfEnabled(SentryLevel.Info, message);
=> logger.LogIfEnabled(SentryLevel.Info, null, message);

/// <summary>
/// Log a info message.
Expand All @@ -52,7 +52,7 @@ public static class DiagnosticLoggerExtensions
this IDiagnosticLogger logger,
string message,
TArg arg)
=> logger.LogIfEnabled(SentryLevel.Info, message, arg);
=> logger.LogIfEnabled(SentryLevel.Info, null, message, arg);

/// <summary>
/// Log a info message.
Expand All @@ -62,7 +62,7 @@ public static class DiagnosticLoggerExtensions
string message,
TArg arg,
TArg2 arg2)
=> logger.LogIfEnabled(SentryLevel.Info, message, arg, arg2);
=> logger.LogIfEnabled(SentryLevel.Info, null, message, arg, arg2);

/// <summary>
/// Log a info message.
Expand All @@ -73,15 +73,15 @@ public static class DiagnosticLoggerExtensions
TArg arg,
TArg2 arg2,
TArg3 arg3)
=> logger.LogIfEnabled(SentryLevel.Info, message, arg, arg2, arg3);
=> logger.LogIfEnabled(SentryLevel.Info, null, message, arg, arg2, arg3);

/// <summary>
/// Log a warning message.
/// </summary>
public static void LogWarning(
this IDiagnosticLogger logger,
string message)
=> logger.LogIfEnabled(SentryLevel.Warning, message);
=> logger.LogIfEnabled(SentryLevel.Warning, null, message);

/// <summary>
/// Log a warning message.
Expand All @@ -90,7 +90,7 @@ public static class DiagnosticLoggerExtensions
this IDiagnosticLogger logger,
string message,
TArg arg)
=> logger.LogIfEnabled(SentryLevel.Warning, message, arg);
=> logger.LogIfEnabled(SentryLevel.Warning, null, message, arg);

/// <summary>
/// Log a warning message.
Expand All @@ -100,49 +100,62 @@ public static class DiagnosticLoggerExtensions
string message,
TArg arg,
TArg2 arg2)
=> logger.LogIfEnabled(SentryLevel.Warning, message, arg, arg2);
=> logger.LogIfEnabled(SentryLevel.Warning, null, message, arg, arg2);

/// <summary>
/// Log a warning message.
/// Log a error message.
/// </summary>
public static void LogError(
this IDiagnosticLogger logger,
string message,
Exception? exception = null)
=> logger.LogIfEnabled(SentryLevel.Error, message, exception);
=> logger.LogIfEnabled(SentryLevel.Error, exception, message);

/// <summary>
/// Log a warning message.
/// Log a error message.
/// </summary>
public static void LogError<TArg>(
this IDiagnosticLogger logger,
string message,
Exception exception,
TArg arg)
=> logger.LogIfEnabled(SentryLevel.Error, message, exception, arg);
=> logger.LogIfEnabled(SentryLevel.Error, exception, message, arg);

/// <summary>
/// Log a warning message.
/// Log a error message.
/// </summary>
public static void LogError<TArg, TArg2>(
this IDiagnosticLogger logger,
string message,
Exception exception,
TArg arg,
TArg2 arg2)
=> logger.LogIfEnabled(SentryLevel.Error, message, exception, arg, arg2);
=> logger.LogIfEnabled(SentryLevel.Error, exception, message, arg, arg2);

/// <summary>
/// Log a warning message.
/// Log a error message.
/// </summary>
public static void LogError<TArg, TArg2, TArg3>(
public static void LogError<TArg, TArg2, TArg3, TArg4>(
this IDiagnosticLogger logger,
string message,
Exception exception,
TArg arg,
TArg2 arg2,
TArg3 arg3,
TArg4 arg4)
=> logger.LogIfEnabled(SentryLevel.Error, exception, message, arg, arg2, arg3, arg4);

/// <summary>
/// Log an error message.
/// </summary>
public static void LogError<TArg, TArg2, TArg3>(
this IDiagnosticLogger logger,
Exception exception,
string message,
TArg arg,
TArg2 arg2,
TArg3 arg3)
=> logger.LogIfEnabled(SentryLevel.Error, message, arg, arg2, arg3, exception);
=> logger.LogIfEnabled(SentryLevel.Error, exception, message, arg, arg2, arg3);

/// <summary>
/// Log a warning message.
Expand All @@ -151,13 +164,13 @@ public static class DiagnosticLoggerExtensions
this IDiagnosticLogger logger,
string message,
Exception? exception = null)
=> logger.LogIfEnabled(SentryLevel.Fatal, message, exception);
=> logger.LogIfEnabled(SentryLevel.Fatal, exception, message);

internal static void LogIfEnabled(
this IDiagnosticLogger logger,
SentryLevel level,
string message,
Exception? exception = null)
Exception? exception,
string message)
{
if (logger.IsEnabled(level))
{
Expand All @@ -168,9 +181,9 @@ public static class DiagnosticLoggerExtensions
internal static void LogIfEnabled<TArg>(
this IDiagnosticLogger logger,
SentryLevel level,
Exception? exception,
string message,
TArg arg,
Exception? exception = null)
TArg arg)
{
if (logger.IsEnabled(level))
{
Expand All @@ -181,10 +194,10 @@ public static class DiagnosticLoggerExtensions
internal static void LogIfEnabled<TArg, TArg2>(
this IDiagnosticLogger logger,
SentryLevel level,
Exception? exception,
string message,
TArg arg,
TArg2 arg2,
Exception? exception = null)
TArg2 arg2)
{
if (logger.IsEnabled(level))
{
Expand All @@ -195,16 +208,32 @@ public static class DiagnosticLoggerExtensions
internal static void LogIfEnabled<TArg, TArg2, TArg3>(
this IDiagnosticLogger logger,
SentryLevel level,
Exception? exception,
string message,
TArg arg,
TArg2 arg2,
TArg3 arg3,
Exception? exception = null)
TArg3 arg3)
{
if (logger.IsEnabled(level))
{
logger.Log(level, message, exception, arg, arg2, arg3);
}
}

internal static void LogIfEnabled<TArg, TArg2, TArg3, TArg4>(
this IDiagnosticLogger logger,
SentryLevel level,
Exception? exception,
string message,
TArg arg,
TArg2 arg2,
TArg3 arg3,
TArg4 arg4)
{
if (logger.IsEnabled(level))
{
logger.Log(level, message, exception, arg, arg2, arg3, arg4);
}
}
}
}

0 comments on commit 53323f0

Please sign in to comment.