Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

renable contrib badge bot, with optional commenting #656

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions OurUmbraco.Client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
"private": true,
"dependencies": {},
"devDependencies": {
"gulp-clean-css": "4.0.0",
"gulp": "4.0.0",
"gulp-autoprefixer": "6.0.0",
"gulp-clean-css": "4.0.0",
"gulp-concat": "2.6.1",
"gulp-imagemin": "5.0.3",
"gulp-jshint": "^2.1.0",
Expand All @@ -18,7 +18,7 @@
"gulp-uglify": "3.0.1",
"gulp-util": "3.0.8",
"gulp-watch": "5.0.1",
"jshint": "^2.9.7",
"jshint": "^2.12.0",
"jshint-stylish": "2.2.1",
"node-sass": "4.14.1"
},
Expand Down
4 changes: 2 additions & 2 deletions OurUmbraco.Site/OurUmbraco.Site.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\UmbracoCms.7.15.3\build\UmbracoCms.props" Condition="Exists('..\packages\UmbracoCms.7.15.3\build\UmbracoCms.props')" />
<Import Project="..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props" Condition="Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" />
<Import Project="..\packages\UmbracoCms.7.15.3\build\UmbracoCms.props" Condition="Exists('..\packages\UmbracoCms.7.15.3\build\UmbracoCms.props')" />
<Import Project="..\packages\LibGit2Sharp.NativeBinaries.1.0.205\build\LibGit2Sharp.NativeBinaries.props" Condition="Exists('..\packages\LibGit2Sharp.NativeBinaries.1.0.205\build\LibGit2Sharp.NativeBinaries.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
Expand Down Expand Up @@ -4535,9 +4535,9 @@
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets'))" />
<Error Condition="!Exists('..\packages\LibGit2Sharp.NativeBinaries.1.0.205\build\LibGit2Sharp.NativeBinaries.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\LibGit2Sharp.NativeBinaries.1.0.205\build\LibGit2Sharp.NativeBinaries.props'))" />
<Error Condition="!Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props'))" />
<Error Condition="!Exists('..\packages\UmbracoCms.7.15.3\build\UmbracoCms.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\UmbracoCms.7.15.3\build\UmbracoCms.props'))" />
<Error Condition="!Exists('..\packages\UmbracoCms.7.15.3\build\UmbracoCms.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\UmbracoCms.7.15.3\build\UmbracoCms.targets'))" />
<Error Condition="!Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props'))" />
</Target>
<Import Project="..\packages\UmbracoCms.7.15.3\build\UmbracoCms.targets" Condition="Exists('..\packages\UmbracoCms.7.15.3\build\UmbracoCms.targets')" />
<Import Project="..\packages\AutoMapper.3.3.1\tools\AutoMapper.targets" Condition="Exists('..\packages\AutoMapper.3.3.1\tools\AutoMapper.targets')" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ public void SendNotification(int topicId, int memberId, NotificationMail notific
{
var memberShipHelper = new MembershipHelper(UmbracoContext.Current);
var member = memberShipHelper.GetById(memberId);


if (member == null)
return;

using (var smtpClient = new SmtpClient())
{
var fromMailAddress = new MailAddress(notificationMail.FromMail, notificationMail.FromName);
Expand Down
35 changes: 19 additions & 16 deletions OurUmbraco/Our/Services/ContributorBadgeService.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using System;
using System.Linq;
using System.Text;
using System.Web.Security;
using Hangfire.Console;
using Hangfire.Console;
using Hangfire.Server;
using OurUmbraco.Community.GitHub;
using OurUmbraco.Our.Models.GitHub;
using OurUmbraco.Our.Models.GitHub.AutoReplies;
using Umbraco.Core;
using System;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Web.Security;
using Umbraco.Core.Models;

namespace OurUmbraco.Our.Services
Expand All @@ -24,9 +24,9 @@ public class ContributorBadgeService
private readonly GitHubService _github;

/// <summary>
/// Indicates whether live mode is activated. If <c>false</c>, the service will not post comments to GitHub.
/// If <c>true</c>, the service will post comments to GitHub, otherwise member profiles are updated silently
/// </summary>
public bool IsLive = false;
public bool EnableComments;

public ContributorBadgeService()
{
Expand All @@ -40,6 +40,13 @@ public ContributorBadgeService()
/// <param name="hangfire">A reference to the Hangfire context if running from Hangfire.</param>
public void CheckContributorBadges(PerformContext hangfire = null)
{
bool.TryParse(ConfigurationManager.AppSettings["EnableContribBadgeBot"], out bool enabled);
if (!enabled)
return;

bool.TryParse(ConfigurationManager.AppSettings["EnableContribBadgeBotComments"], out bool enableComments);
EnableComments = enableComments;

CheckContributorBadges(DateTime.UtcNow.Subtract(TimeSpan.FromDays(10)), hangfire);
}

Expand Down Expand Up @@ -72,10 +79,6 @@ public void CheckContributorBadges(DateTime since, PerformContext hangfire = nul
/// <param name="hangfire">A reference to the Hangfire context if running from Hangfire.</param>
public void CheckContributorBadges(Issue pr, PerformContext hangfire = null)
{

if (IsLive == false)
return;

string prefix = $"[{pr.RepoSlug}/{pr.Number}]";

// Look for a "merged" event in the list of events
Expand Down Expand Up @@ -110,7 +113,7 @@ public void CheckContributorBadges(Issue pr, PerformContext hangfire = null)
}

// Add the comment to the issue on GitHub
if (IsLive) _github.AddCommentToIssue(pr, GitHubAutoReplyType.ContributorsBadgeMemberNotFound, GetContributorBadgeMemberNotFoundMessage(pr));
if (EnableComments) _github.AddCommentToIssue(pr, GitHubAutoReplyType.ContributorsBadgeMemberNotFound, GetContributorBadgeMemberNotFoundMessage(pr));

return;
}
Expand All @@ -126,7 +129,7 @@ public void CheckContributorBadges(Issue pr, PerformContext hangfire = null)
Roles.AddUserToRole(creator.Email, Constants.MemberGroups.Contributor);

// Add the comment to the issue on GitHub
if (IsLive) _github.AddCommentToIssue(pr, GitHubAutoReplyType.ContributorsBadgeAdded, GetContributorBadgeAddedMessage(pr, creator));
if (EnableComments) _github.AddCommentToIssue(pr, GitHubAutoReplyType.ContributorsBadgeAdded, GetContributorBadgeAddedMessage(pr, creator));

hangfire.WriteLine($"{prefix} Creator {pr.User.Login} has successfully been given the contributors badge");

Expand All @@ -144,7 +147,7 @@ private string GetContributorBadgeMemberNotFoundMessage(Issue issue)
sb.AppendLine("Hi @" + issue.User.Login + ",");
sb.AppendLine();

sb.Append($"We really wish to give you the [**Contributors badge**]({ourBadgeUrl}) badge on **Our Umbraco**, ");
sb.Append($"We'd loved to give you the [**Contributors badge**]({ourBadgeUrl}) badge on **Our Umbraco**, ");
sb.Append("but we haven't been able to find an account on Our Umbraco matching your GitHub ID.");
sb.AppendLine();
sb.AppendLine();
Expand Down Expand Up @@ -173,7 +176,7 @@ private string GetContributorBadgeAddedMessage(Issue issue, IMember member)
sb.AppendLine("Hi @" + issue.User.Login + ",");
sb.AppendLine();

sb.Append("As a appreciation for your merged PR, you have now been given the");
sb.Append("As a token of appreciation for your merged PR, you have now been given the");
sb.Append($"[**Contributors badge**]({ourBadgeUrl}) badge on **Our Umbraco** - the official Umbraco community forum.");
sb.AppendLine();
sb.AppendLine();
Expand Down