-
Couldn't load subscription status.
- Fork 86
Sync repo #1143
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
Sync repo #1143
Conversation
| end | ||
| defp add_merged(%Ecto.Changeset{} = changeset) do | ||
| changeset |> put_change(:merged, false) | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently GitHub does not pass merged along when listing the records.
Can also remove:
additions changed_files comments commits deletions mergeable_state review_comments
|
I will mention that it is really, really hard to debug problems happening inside of these |
|
I fixed an issue where I wanted to at least get this spike working before worrying too much about error handling. Hard to get it working without it, though. |
|
I managed to debug it. I'm getting a single task back that's got an It turns out this is due to a bug: we're not setting the Of course, this means my strategy here is probably flawed. We won't get back updated issues/tasks when a sync isn't happening for the first time. We could modify this by returning back the matched issues regardless of whether the sync happens. That would allow my strategy here to continue to work. But it's probably worth stepping back and re-evaluating this approach. That said, the general outline of how to approach the problem is there as a start. |
|
I ran a |
lib/code_corps/github/sync/sync.ex
Outdated
| tasks = Enum.map(tasks, fn task -> {:ok, task} end) | ||
| sync_comments(repo, github_issues, tasks) | ||
| repo | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inside here we could sync each step, modify the GithubRepo sync state, and then return the repo when done.
|
@joshsmith I managed to spike out a less coupled, fully working Problems
|
|
We could speed up comment fetching with |
|
From our chat offline, what we need to do here
|
|
For adding
|
|
This is going to need some significant cleanup of changesets and the way changes are propagated to the various GithubX models during sync. |
|
This is mostly working, but on a first pass through a project, it seems to not create tasks in the |
|
I wonder if it is worth adding in a |
|
My first goals tomorrow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is pretty much implemented the way I would continue off.
I got a suggested issue for adapter behavior, but that's about it.
| github_issue | ||
| |> Map.from_struct | ||
| |> MapTransformer.transform_inverse(@issue_mapping) | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The naming makes sense, but considering we were switching already, I'm thinking maybe we want to write a behavior module and document what an adapter needs to look like and what the naming convention is.
I'm just imagining where, in a couple of weeks, I write a new one and end up using a new scheme because I wasn't 100% what the old one is.
|
This is missing tests for the |
35b302b to
76acde5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some notes on things we can still improve here.
| |> unique_github_constraint() | ||
| end | ||
|
|
||
| def update_with_github_user_changeset(struct, %{} = params) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing spec and docs.
| {:url, ["url"]} | ||
| ] | ||
|
|
||
| def to_comment_attrs(%GithubComment{} = github_comment) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing spec and docs.
| end | ||
|
|
||
| def to_issue_attrs(%GithubIssue{} = github_issue) do | ||
| github_issue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing spec and docs.
| |> ResultAggregator.aggregate | ||
| end | ||
|
|
||
| def sync_project_github_repo(%ProjectGithubRepo{github_repo: %GithubRepo{} = _} = project_github_repo) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing spec and doc.
| |> ResultAggregator.aggregate | ||
| end | ||
|
|
||
| def sync_project_github_repo(%ProjectGithubRepo{github_repo: %GithubRepo{} = _} = project_github_repo) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing spec and doc.
| end | ||
| end | ||
|
|
||
| defp put_sync_opt(opts, key, map) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing spec and doc.
| end | ||
|
|
||
| @spec sync_repo(GithubRepo.t) :: {:ok, GithubRepo.t} | ||
| def sync_repo(%GithubRepo{} = repo) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing doc.
| end | ||
| end | ||
|
|
||
| def sync_project_github_repo(%ProjectGithubRepo{} = project_github_repo) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing spec and doc.
| nil -> changeset | ||
| _ -> do_validate_time_after(changeset, field, previous_time, current_time) | ||
| end | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs updated unit tests.
| {:ok, :authorized} <- current_user |> Policy.authorize(:create, %ProjectGithubRepo{}, params), | ||
| {:ok, %ProjectGithubRepo{} = project_github_repo} <- create_project_repo_changeset(params) |> Repo.insert do | ||
|
|
||
| TaskSupervisor.start_child(:background_processor, fn -> CodeCorps.GitHub.Sync.sync_project_github_repo(project_github_repo) end) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not tested anywhere right now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of ideas I have, plus a potential change that needs to be reverted, but other than that, this looks great!
|
|
||
| with {:ok, project_github_repo} <- project_github_repo |> mark_project_repo("syncing_github_repo"), | ||
| {:ok, %GithubRepo{sync_state: "receiving_webhooks"}} <- repo |> sync_repo(), | ||
| project_github_repo <- Repo.get(ProjectGithubRepo, project_github_repo.id) |> preload_project_github_repo(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd actually prefer something like
preloads <- [:project, github_repo: [:github_app_installation, [github_issues: [:github_comments, :github_user]]]],
project_github_repo <- project_github_repo |> Repo.preload(preloads)I think it's actually easier to follow. Either that, or renaming preload_project_gihub_repo to load_associations.
Seems somewhat more explicit to me.
| {:ok, %GithubRepo{sync_state: "receiving_webhooks"}} <- repo |> sync_repo(), | ||
| project_github_repo <- Repo.get(ProjectGithubRepo, project_github_repo.id) |> preload_project_github_repo(), | ||
| {:ok, project_github_repo} <- project_github_repo |> mark_project_repo("syncing_tasks"), | ||
| {:ok, _tasks} <- project_github_repo |> Sync.Issue.Task.sync_project_github_repo() |> sync_step(:sync_tasks), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trying to read Sync.Issue.Task.sync_project_github_repo makes me think we may have nested too deep.
project_github_repo |> Sync.TaskSyncer.syncLooks a bit clearer, but I'm still not happy with it. However, the we could alias Sync.TaskSyncer and just call
project_github_repo |> TaskSyncer.syncWhat do you think about flattening out our Sync namespace that way? Nesting Task and GithubIssue under Issue together seems like we did just for the sake of them being semantically related, but logically, we probably want the two processes as decoupled as possible.
sync/sync.ex
sync/task_syncer.ex
sync/github_issue_syncer.ex
etc. looks nicer to me.
For now, as part of this PR, I'm thinking we
alias CodeCorps.GitHub.Sync.Issue.Task, as: TaskSyncerand do the same for other modules. What do you think?
lib/code_corps/github/sync/sync.ex
Outdated
| defp marshall_result({:ok, %{github_pull_request: _, github_issue: _}} = result), do: result | ||
| defp marshall_result({:ok, %{github_pull_request: pull_request}}), do: {:ok, pull_request} | ||
| defp marshall_result({:ok, %{github_issue: _, tasks: _}} = result), do: result | ||
| defp marshall_result({:ok, %{github_issue: github_issue}}), do: {:ok, github_issue} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these still needed? I think we didn't touch transactions in this PR
e0dab0a to
6141cc3
Compare
18dd750 to
33cf7b3
Compare
What's in this PR?
This is almost good to merge now.
Closes #1111
Closes #1133
Closes #1136
Closes #971