Repository navigation
Expand file tree
/
Copy pathRepositoryChannels.cs
More file actions
102 lines (82 loc) · 3.66 KB
/
Copy pathRepositoryChannels.cs
File metadata and controls
102 lines (82 loc) · 3.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Copyright (c) 2019-2026 ReactiveUI and Contributors. All rights reserved.
// ReactiveUI and Contributors licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.
using ReactiveUI.Binding.Documentation.GitHub;
using ReactiveUI.Primitives.Signals;
namespace ReactiveUI.Binding.Documentation.Observing;
/// <summary>
/// The live event streams of one repository, one stream per kind of activity. The server pushes an event onto the
/// stream that matches it, and every subscriber of that stream hears it.
/// </summary>
[System.Diagnostics.DebuggerDisplay("RepositoryChannels: {Repository}")]
public sealed class RepositoryChannels : IDisposable
{
/// <summary>Every stream the repository owns.</summary>
private readonly Signal<string>[] _streams;
/// <summary>Initializes a new instance of the <see cref="RepositoryChannels"/> class.</summary>
/// <param name="repository">The repository the streams belong to.</param>
public RepositoryChannels(Repository repository)
{
Repository = repository;
_streams =
[
IssueOpened,
IssueClosed,
IssueReopened,
IssueAssigned,
IssueLabelled,
CommentAdded,
CommentEdited,
MilestoneChanged,
PullRequestOpened,
PullRequestMerged,
ReviewRequested,
ReleasePublished,
];
}
/// <summary>Gets the repository the streams belong to.</summary>
public Repository Repository { get; }
/// <summary>Gets the stream of newly opened issues.</summary>
public Signal<string> IssueOpened { get; } = new();
/// <summary>Gets the stream of closed issues.</summary>
public Signal<string> IssueClosed { get; } = new();
/// <summary>Gets the stream of reopened issues.</summary>
public Signal<string> IssueReopened { get; } = new();
/// <summary>Gets the stream of issue assignments.</summary>
public Signal<string> IssueAssigned { get; } = new();
/// <summary>Gets the stream of issue labels.</summary>
public Signal<string> IssueLabelled { get; } = new();
/// <summary>Gets the stream of new comments.</summary>
public Signal<string> CommentAdded { get; } = new();
/// <summary>Gets the stream of edited comments.</summary>
public Signal<string> CommentEdited { get; } = new();
/// <summary>Gets the stream of milestone changes.</summary>
public Signal<string> MilestoneChanged { get; } = new();
/// <summary>Gets the stream of newly opened pull requests.</summary>
public Signal<string> PullRequestOpened { get; } = new();
/// <summary>Gets the stream of merged pull requests.</summary>
public Signal<string> PullRequestMerged { get; } = new();
/// <summary>Gets the stream of review requests.</summary>
public Signal<string> ReviewRequested { get; } = new();
/// <summary>Gets the stream of published releases.</summary>
public Signal<string> ReleasePublished { get; } = new();
/// <summary>Gets how many streams currently have a subscriber.</summary>
public int SubscribedStreamCount => _streams.Count(static stream => stream.HasObservers);
/// <summary>Publishes one announcement, such as a maintenance window, on every stream.</summary>
/// <param name="text">The announcement.</param>
public void PublishNotice(string text)
{
for (var i = 0; i < _streams.Length; i++)
{
_streams[i].OnNext(text);
}
}
/// <inheritdoc/>
public void Dispose()
{
for (var i = 0; i < _streams.Length; i++)
{
_streams[i].Dispose();
}
}
}