/// <summary> /// Calculates the change to a <paramref name="goodBoyPointsEntry"/> given a set of <paramref name="labels"/> /// </summary> /// <param name="goodBoyPointsEntry">The <see cref="GoodBoyPointsEntry"/> to adjust</param> /// <param name="offset">The <see cref="GoodBoyPointsOffset"/> to apply to the result</param> /// <param name="labels">The <see cref="Label"/>s to make adjustments from</param> /// <returns>A new <see cref="GoodBoyPointsEntry"/> based off changing <paramref name="goodBoyPointsEntry"/> with <paramref name="labels"/></returns> static GoodBoyPointsEntry AdjustGBP(GoodBoyPointsEntry goodBoyPointsEntry, GoodBoyPointsOffset offset, IEnumerable <Label> labels) { var result = new GoodBoyPointsEntry { Points = goodBoyPointsEntry.Points }; foreach (var L in labels) { switch (L.Name) { case "PRB: No Update": return(new GoodBoyPointsEntry { Points = goodBoyPointsEntry.Points }); case "PRB: Reset": return(new GoodBoyPointsEntry()); default: if (LabelValues.TryGetValue(L.Name, out int award)) { result.Points += award; } break; } } result.Points += offset?.Offset ?? 0; return(result); }
/// <summary> /// Set the <paramref name="offset"/> for a <paramref name="prNumber"/> /// </summary> /// <param name="prNumber">The <see cref="Octokit.PullRequest.Number"/></param> /// <param name="offset">The <see cref="GoodBoyPointsOffset"/> for <paramref name="prNumber"/></param> /// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param> /// <returns>A <see cref="Task"/> representing the running operation</returns> public Task SetOffset(int prNumber, GoodBoyPointsOffset offset, CancellationToken cancellationToken) => dataStore.WriteData(prNumber.ToString(), offset ?? throw new ArgumentNullException(nameof(offset)), cancellationToken);