Skip to content

Commit

Permalink
Merge pull request #82 from abhinavminhas/dev
Browse files Browse the repository at this point in the history
Nuget Package Creation - v1.10.0
  • Loading branch information
abhinavminhas authored Aug 3, 2024
2 parents d4c6b5b + 5c4775b commit 76aa8dc
Show file tree
Hide file tree
Showing 13 changed files with 337 additions and 141 deletions.
46 changes: 45 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#CI/MANUAL TRIGGER
name: Build
name: Build / Test

on:
push:
Expand All @@ -12,6 +12,7 @@ on:

jobs:
Build_DotNet_OS-VSVersion:
name: Build/Test (.NET Framework)
runs-on: ${{ matrix.os }}
strategy:
matrix:
Expand Down Expand Up @@ -65,6 +66,7 @@ jobs:


Build_DotNetCore_OS-Version:
name: Build (.NET Core)
runs-on: ${{ matrix.os }}
strategy:
matrix:
Expand Down Expand Up @@ -110,6 +112,7 @@ jobs:
run: dotnet test --no-build --verbosity normal --configuration Release --filter TestCategory=GMAIL-TESTS-DOTNETCORE

Code-Coverage:
name: Code Coverage (Codecov)
runs-on: ${{ matrix.os }}
strategy:
matrix:
Expand Down Expand Up @@ -158,3 +161,44 @@ jobs:
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}

Code-Quality:
name: Code Quality (SonarCloud)
runs-on: windows-latest
steps:
- name: Setup JDK 17
uses: actions/setup-java@v4
with:
java-version: 17
distribution: 'zulu'
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Cache SonarCloud Packages
uses: actions/cache@v4
with:
path: ~\sonar\cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache SonarCloud Scanner
id: cache-sonar-scanner
uses: actions/cache@v4
with:
path: .\.sonar\scanner
key: ${{ runner.os }}-sonar-scanner
restore-keys: ${{ runner.os }}-sonar-scanner
- name: Install SonarCloud Scanner
if: steps.cache-sonar-scanner.outputs.cache-hit != 'true'
shell: powershell
run: |
New-Item -Path .\.sonar\scanner -ItemType Directory
dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner
- name: Build And Analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
shell: powershell
run: |
.\.sonar\scanner\dotnet-sonarscanner begin /k:"abhinavminhas_Gmail-API-Helper" /o:"abhinavminhas" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io"
dotnet build
.\.sonar\scanner\dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
45 changes: 45 additions & 0 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Code Quality (SonarCloud)
on:
workflow_dispatch:

jobs:
build:
name: Code Quality (SonarCloud)
runs-on: windows-latest
steps:
- name: Set Up JDK 17
uses: actions/setup-java@v4
with:
java-version: 17
distribution: 'zulu'
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Cache SonarCloud Packages
uses: actions/cache@v4
with:
path: ~\sonar\cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache SonarCloud Scanner
id: cache-sonar-scanner
uses: actions/cache@v4
with:
path: .\.sonar\scanner
key: ${{ runner.os }}-sonar-scanner
restore-keys: ${{ runner.os }}-sonar-scanner
- name: Install SonarCloud Scanner
if: steps.cache-sonar-scanner.outputs.cache-hit != 'true'
shell: powershell
run: |
New-Item -Path .\.sonar\scanner -ItemType Directory
dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner
- name: Build And Analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
shell: powershell
run: |
.\.sonar\scanner\dotnet-sonarscanner begin /k:"abhinavminhas_Gmail-API-Helper" /o:"abhinavminhas" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io"
dotnet build
.\.sonar\scanner\dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
1 change: 1 addition & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:

jobs:
build:
name: Code Coverage (Codecov)
runs-on: ${{ matrix.os }}
strategy:
matrix:
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/publish-nuget-Package.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
name: Publish Nuget Package

env:
NUGET_PACKAGE_NAME_VERSION: "GmailHelper.1.9.31.nupkg"
NUGET_PACKAGE_NAME_VERSION: "GmailHelper.1.10.0.nupkg"

on:
workflow_dispatch:

jobs:
build:
name: Publish Nuget Package
runs-on: ${{ matrix.os }}
strategy:
matrix:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ name: Test CleanUp

on:
workflow_run:
workflows: [ Build ]
workflows: [ Build / Test ]
branches: [ main, dev ]
types: [ completed ]
workflow_dispatch:

jobs:
build:
name: Test Cleanup
runs-on: ${{ matrix.os }}
strategy:
matrix:
Expand Down
34 changes: 34 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,40 @@ All notable changes to this project documented here.

## [Released]

## [1.10.0](https://www.nuget.org/packages/GmailHelper/1.10.0) - 2024-08-04
### Changed
* Security Updates
* Remove security protocol usage completely _(Due to deprecated versions in .Net Standard 2.0, should rely on .NET version's security protocol using this package)_.
* Email regex match - Introduce timeout to limit the execution time (DDoS protection).
* Code Quality Updates
* Remove null execution path (below impacted)
* GetMessage
* GetLatestMessage
* GetMessageAttachments
* MoveMessageToTrash
* UntrashMessage
* ReportSpamMessage
* UnspamMessage
* MarkMessageAsRead
* MarkMessageAsUnread
* ModifyMessage
* GetMessageLabels
* Merge if statement with the enclosing if statement (below impacted)
* GetMessageAttachments
* GetMessagesAttachments
* Remove useless assignment to local variable 'requiredMessagePart' (below impacted)
* GetLatestMessage
* Throw 'ArgumentException' instead of 'NullReferenceException' (below impacted)
* ModifyMessage
* ModifyMessages
* Define a constant instead of using the literal multiple times for
* 'token.json'
* 'INBOX'
* 'SPAM'
* Remove member variables and declare it as a local variable in the relevant methods
* _scope
* _applicationName

## [1.9.31](https://www.nuget.org/packages/GmailHelper/1.9.31) - 2024-07-23
### Changed
- MimeKitLite dependency update from ('4.7.0' -> '4.7.1').
Expand Down
37 changes: 27 additions & 10 deletions GmailAPIHelper.CORE.Tests/GmailTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;

namespace GmailAPIHelper.CORE.Tests
{
Expand Down Expand Up @@ -75,10 +76,19 @@ public void Test_GetGmailService_TokenPath_Home()
destPath = Environment.GetEnvironmentVariable("HOME") + "/" + "token.json";
Directory.CreateDirectory(destPath);
File.Copy(sourcePath, destPath + "/Google.Apis.Auth.OAuth2.Responses.TokenResponse-user", overwrite: true);
GmailHelper.GetGmailService(ApplicationName, GmailHelper.TokenPathType.HOME);
var service = GmailHelper.GetGmailService(ApplicationName, GmailHelper.TokenPathType.HOME);
Assert.IsTrue(service.GetType() == typeof(Google.Apis.Gmail.v1.GmailService));
Directory.Delete(destPath, recursive: true);
}

[TestMethod]
[TestCategory("GMAIL-TESTS-DOTNETCORE")]
public void Test_GetGmailService_TokenPath_WorkingDirectory()
{
var service = GmailHelper.GetGmailService(ApplicationName, GmailHelper.TokenPathType.WORKING_DIRECTORY);
Assert.IsTrue(service.GetType() == typeof(Google.Apis.Gmail.v1.GmailService));
}

[TestMethod]
[TestCategory("GMAIL-TESTS-DOTNETCORE")]
public void Test_GetGmailService_TokenPath_Custom()
Expand All @@ -90,7 +100,8 @@ public void Test_GetGmailService_TokenPath_Custom()
credPath = Environment.CurrentDirectory + "/" + "token.json";
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
credPath = Environment.CurrentDirectory + "/" + "token.json";
GmailHelper.GetGmailService(ApplicationName, GmailHelper.TokenPathType.CUSTOM, credPath);
var service = GmailHelper.GetGmailService(ApplicationName, GmailHelper.TokenPathType.CUSTOM, credPath);
Assert.IsTrue(service.GetType() == typeof(Google.Apis.Gmail.v1.GmailService));
}

[TestMethod]
Expand Down Expand Up @@ -365,6 +376,7 @@ public void Test_SendMessage_PlainText()
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
path = Environment.CurrentDirectory + "/TestFiles/PlainEmail.txt";
var body = File.ReadAllText(path);
Assert.IsFalse(Regex.IsMatch(body, "<(.|\n)*?>", RegexOptions.None, TimeSpan.FromMilliseconds(100)));
GmailHelper.GetGmailService(ApplicationName)
.SendMessage(GmailHelper.EmailContentType.PLAIN, TestEmailId, cc: TestEmailId, bcc: TestEmailId, subject: "EMAIL WITH PLAIN TEXT", body: body);
}
Expand All @@ -381,6 +393,7 @@ public void Test_SendMessage_HtmlText()
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
path = Environment.CurrentDirectory + "/TestFiles/HTMLEmail.txt";
var body = File.ReadAllText(path);
Assert.IsTrue(Regex.IsMatch(body, "<(.|\n)*?>", RegexOptions.None, TimeSpan.FromMilliseconds(100)));
GmailHelper.GetGmailService(ApplicationName)
.SendMessage(GmailHelper.EmailContentType.HTML, TestEmailId, cc: TestEmailId, bcc: TestEmailId, subject: "EMAIL WITH HTML TEXT", body: body);
}
Expand Down Expand Up @@ -463,6 +476,7 @@ public void Test_SendMessage_Attachments_PlainText()
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
path = Environment.CurrentDirectory + "/TestFiles/PlainEmail.txt";
var body = File.ReadAllText(path);
Assert.IsFalse(Regex.IsMatch(body, "<(.|\n)*?>", RegexOptions.None, TimeSpan.FromMilliseconds(100)));
var attachmentPath = "";
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
attachmentPath = Environment.CurrentDirectory + "\\TestFiles\\Attachments\\";
Expand Down Expand Up @@ -499,6 +513,7 @@ public void Test_SendMessage_Attachments_HtmlText()
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
path = Environment.CurrentDirectory + "/TestFiles/HTMLEmail.txt";
var body = File.ReadAllText(path);
Assert.IsTrue(Regex.IsMatch(body, "<(.|\n)*?>", RegexOptions.None, TimeSpan.FromMilliseconds(100)));
var attachmentPath = "";
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
attachmentPath = Environment.CurrentDirectory + "\\TestFiles\\Attachments\\";
Expand Down Expand Up @@ -1086,7 +1101,7 @@ public void Test_ModifyMessage_NoLabelsSupplied()
Assert.Fail("No Exception Thrown.");
}
catch (AssertFailedException ex) { throw ex; }
catch (NullReferenceException ex) { Assert.AreEqual("Either 'Labels To Add' or 'Labels to Remove' required.", ex.Message); }
catch (ArgumentException ex) { Assert.AreEqual("Parameters 'labelsToAdd' / 'labelsToRemove' required.", ex.Message); }
}

[TestMethod]
Expand Down Expand Up @@ -1141,7 +1156,7 @@ public void Test_ModifyMessages_NoLabelsSupplied()
Assert.Fail("No Exception Thrown.");
}
catch (AssertFailedException ex) { throw ex; }
catch (NullReferenceException ex) { Assert.AreEqual("Either 'Labels To Add' or 'Labels to Remove' required.", ex.Message); }
catch (ArgumentException ex) { Assert.AreEqual("Parameters 'labelsToAdd' / 'labelsToRemove' required.", ex.Message); }
}

[TestMethod]
Expand Down Expand Up @@ -1484,18 +1499,20 @@ public void Test_ListUserLabels()
[TestCategory("TestCleanup")]
public void Inbox_CleanUp()
{
GmailHelper.GetGmailService(ApplicationName)
var mesagesMoved = 0;
mesagesMoved += GmailHelper.GetGmailService(ApplicationName)
.MoveMessagesToTrash(query: $"[from:{TestEmailId}]in:inbox is:unread");
GmailHelper.GetGmailService(ApplicationName)
mesagesMoved += GmailHelper.GetGmailService(ApplicationName)
.MoveMessagesToTrash(query: $"[from:{TestEmailId}]in:spam is:unread");
GmailHelper.GetGmailService(ApplicationName)
mesagesMoved += GmailHelper.GetGmailService(ApplicationName)
.MoveMessagesToTrash(query: "[subject:'MARK DOTNETCORE MESSAGE AS READ']in:inbox is:read");
GmailHelper.GetGmailService(ApplicationName)
mesagesMoved += GmailHelper.GetGmailService(ApplicationName)
.MoveMessagesToTrash(query: "[subject:'MARK DOTNETFRAMEWORK MESSAGE AS READ']in:inbox is:read");
GmailHelper.GetGmailService(ApplicationName)
mesagesMoved += GmailHelper.GetGmailService(ApplicationName)
.MoveMessagesToTrash(query: "[subject:'MARK DOTNETCORE MESSAGES AS READ']in:inbox is:read");
GmailHelper.GetGmailService(ApplicationName)
mesagesMoved += GmailHelper.GetGmailService(ApplicationName)
.MoveMessagesToTrash(query: "[subject:'MARK DOTNETFRAMEWORK MESSAGES AS READ']in:inbox is:read");
Assert.IsTrue(mesagesMoved >= 0);
}
}
}
1 change: 0 additions & 1 deletion GmailAPIHelper.CORE.Tests/TestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

namespace GmailAPIHelper.CORE.Tests
{
[TestClass]
public class TestBase
{
private TestContext _testContextInstance;
Expand Down
Loading

0 comments on commit 76aa8dc

Please sign in to comment.