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

GitHub actions vnext #1

Open
wants to merge 6 commits into
base: master
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
43 changes: 43 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: CI
on: push

jobs:
build:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v1
- uses: actions/setup-dotnet@v1
with:
dotnet-version: "2.2.300"
- name: .NET Test
run: dotnet test --filter TestCategory!=GDI
env:
Apetito__EMail: ${{ secrets.Apetito__EMail }}
Apetito__Password: ${{ secrets.Apetito__Password }}
- name: .NET Publish
run: dotnet publish ApetitOMate.Function -c Release -o ./publish
- name: Upload Artifact
uses: actions/upload-artifact@v1
with:
name: publish
path: ApetitOMate.Function/publish

deploy:
if: github.ref == 'refs/heads/github-actions-vnext'
needs: build
runs-on: ubuntu-18.04
steps:
- name: Download Artifact
uses: actions/download-artifact@v1
with:
name: publish
- name: Login via Azure CLI
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_SECRET }}
- name: Deploy Azure Function
uses: Azure/functions-action@v1
id: fa
with:
app-name: ApetitOMate
package: ./publish
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ bin/
obj/
ApetitOMate.ini
local.settings.json
node_modules/
node_modules/
__blobstorage__
__azurite_*
package-lock.json
39 changes: 9 additions & 30 deletions ApetitOMate.Core/Action/ActivateTableGuestAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,52 +9,31 @@ namespace ApetitOMate.Core.Action
{
public class ActivateTableGuestAction
{
private const string ActivationSubject = "Apetito Account Activated";
private const string ActivationText =
@"Your Apetito account has been activated.

You can now login via: https://www.mylunch-apetito.de/
";
private readonly ApetitoConfig apetitoConfig;
private readonly ApetitoApi apetitoApi;
private readonly MailClient mailClient;

public ActivateTableGuestAction(ApetitoConfig apetitoConfig, ApetitoApi apetitoApi, MailClient mailClient)
public ActivateTableGuestAction(ApetitoConfig apetitoConfig, ApetitoApi apetitoApi)
{
this.apetitoConfig = apetitoConfig;
this.apetitoApi = apetitoApi;
this.mailClient = mailClient;
}

public async Task<TableGuest[]> Run()
{
var activated = new List<TableGuest>();
TableGuest[] guests = await this.apetitoApi.GetTableGuests();
foreach (TableGuest disabledGuest in guests.Where(guest => guest.IsLocked == true && HasAccountDomain(guest)))
{
disabledGuest.IsLocked = false;

if (this.apetitoConfig.DefaultGroupName != null)
{
TableGuestGroup[] groups = await this.apetitoApi.GetTableGuestGroups();
var defaultGroup = groups.FirstOrDefault(group => group.GroupName == this.apetitoConfig.DefaultGroupName);
if (defaultGroup != null)
{
disabledGuest.SetGroup(defaultGroup);
}
}

TableGuest updated = await this.apetitoApi.UpdateTableGuest(disabledGuest.Id, disabledGuest);

await this.mailClient.Send(ActivationSubject, ActivationText, updated.EmailAddress);
activated.Add(updated);
}

return activated.ToArray();
TableGuest[] unactivatedGuests = guests.Where(guest => guest.Status == TableGuest.RegistrationStatus.Registered && HasAccountDomain(guest)).ToArray();
await this.apetitoApi.ActivateTableGuests(unactivatedGuests);
return unactivatedGuests;
}

private bool HasAccountDomain(TableGuest guest)
{
if (guest.EmailAddress.Contains("apetitotest1"))
{
return false;
}

var domain = this.apetitoConfig.EMail.Split('@', 2).Last();
return guest.EmailAddress.EndsWith(domain, StringComparison.InvariantCultureIgnoreCase);
}
Expand Down
5 changes: 3 additions & 2 deletions ApetitOMate.Core/Api/Apetito/ApetitoApi.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.IO;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
Expand All @@ -13,8 +14,8 @@ public interface ApetitoApi
[Get("tableguest/TableGuests/<customerId>")]
Task<TableGuest[]> GetTableGuests();

[Put("tableguest/TableGuests/<customerId>/{guestId}")]
Task<TableGuest> UpdateTableGuest([Path] int guestId, [Body] TableGuest guest);
[Post("tableguest/TableGuests/register/<customerId>/AccountActivation")]
Task ActivateTableGuests([Body] params TableGuest[] guests);

[Get("tableguest/tableguestgroups/<customerId>")]
Task<TableGuestGroup[]> GetTableGuestGroups();
Expand Down
23 changes: 22 additions & 1 deletion ApetitOMate.Core/Api/Apetito/TableGuest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,23 @@ public class TableGuest
{
private readonly JObject backing;

public int Id => this.backing.Value<int>(nameof(Id));
public Guid Id => Guid.Parse(this.backing.Value<string>(nameof(Id)));

public string EmailAddress => this.backing.Value<string>(nameof(EmailAddress));

public RegistrationStatus? Status
{
get
{
if (Enum.TryParse<RegistrationStatus>(this.backing.Value<string>(nameof(Status)), true, out RegistrationStatus value))
{
return value;
}
return null;
}
set => this.backing[nameof(Status)] = Enum.GetName(typeof(RegistrationStatus), value);
}

public bool IsLocked
{
get => this.backing.Value<bool>(nameof(IsLocked));
Expand Down Expand Up @@ -44,5 +57,13 @@ public override TableGuest ReadJson(JsonReader reader, Type objectType, TableGue
return new TableGuest(serializer.Deserialize<JObject>(reader));
}
}


public enum RegistrationStatus
{
InvitationSend = 1,
Registered = 2,
Activated = 3
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace ApetitOMate.Core.Action
public class UnfulfilledOrderRetrieverTest
{
[Test]
[Ignore("Sadly the unfulfilled orders have been deleted")]
public async Task Test()
{
var retriever = new UnfulfilledOrderRetriever(new ApetitoApiFactory(Config.Instance.ApetitoConfig).Build());
Expand Down
9 changes: 2 additions & 7 deletions ApetitOMate.Core_Test/Api/Apetito/ApetitoApiTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public async Task TestGetOrders()


[Test]
[Ignore("Sadly the unfulfilled orders have been deleted")]
public async Task TestIncompleteOrders()
{
Order[] guests = await this.api.GetOrders("2019-03-01");
Expand All @@ -39,15 +40,9 @@ public async Task TestGetTableGuests()
{
TableGuest[] guests = await this.api.GetTableGuests();
guests.Where(guest => guest.EmailAddress.EndsWith("@cqse.eu")).Should().NotBeEmpty();
foreach (TableGuest disabledGuest in guests.Where(guest => guest.IsLocked == true))
{
disabledGuest.IsLocked = false;
TableGuest updated = await this.api.UpdateTableGuest(disabledGuest.Id, disabledGuest);
updated.IsLocked.Should().BeFalse();
}

}


[Test]
public async Task TestGetTableGuestGroups()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging;

namespace ApetitOMate.Function.Mail
namespace ApetitOMate.Function
{
public static class ActivateTableGuests
{
Expand All @@ -38,17 +38,13 @@ private static async Task<TableGuest[]> ActivateGuests(ILogger log)
try
{
Config config = Config.Instance;
using (MailClient mailClient = new MailClientFactory(config.MailConfig).Build())
{
TableGuest[] activated = await new ActivateTableGuestAction(
config.ApetitoConfig,
new ApetitoApiFactory(config.ApetitoConfig).Build(),
mailClient
).Run();
TableGuest[] activated = await new ActivateTableGuestAction(
config.ApetitoConfig,
new ApetitoApiFactory(config.ApetitoConfig).Build()
).Run();

log.LogInformation($"Activated {activated.Length} guests: " + string.Join(", ", activated.Select(a => a.EmailAddress)));
return activated;
}
log.LogInformation($"Activated {activated.Length} guests: " + string.Join(", ", activated.Select(a => a.EmailAddress)));
return activated;
}
catch (Exception e)
{
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# ApetitOMate [![Build Status](https://travis-ci.com/mpdeimos/ApetitOMate.svg?token=s9W6xLGWTxNAz3Wyskvq&branch=master)](https://travis-ci.com/mpdeimos/ApetitOMate) [![GitHub Actions](https://wdp9fww0r9.execute-api.us-west-2.amazonaws.com/production/badge/mpdeimos/ApetitOMate)](https://github.com/mpdeimos/ApetitOMate/actions)
# ApetitOMate [![Build Status](https://travis-ci.com/mpdeimos/ApetitOMate.svg?token=s9W6xLGWTxNAz3Wyskvq&branch=master)](https://travis-ci.com/mpdeimos/ApetitOMate) [![GitHub Actions](https://github.com/mpdeimos/ApetitOMate/workflows/CI/badge.svg)](https://github.com/mpdeimos/ApetitOMate/actions)

Automation for Apetito Lunch Service

## TODO
Expand Down