| 54 | } |
| 55 | |
| 56 | func (a *Application) Parse(issue *github.Issue) { |
| 57 | a.validator = Validator{} |
| 58 | |
| 59 | if strings.Contains(*issue.Title, "[project name]") { |
| 60 | a.validator.AddError("Application title", *issue.Title, "is missing project name") |
| 61 | } |
| 62 | |
| 63 | a.sections = a.extractSections(*issue.Body) |
| 64 | |
| 65 | if isTesting() { |
| 66 | data, err := json.MarshalIndent(a.sections, "", "\t") |
| 67 | if err != nil { |
| 68 | sentry.CaptureException(err) |
| 69 | log.Fatalf("Could not marshal Sections input data: %s", err.Error()) |
| 70 | } |
| 71 | |
| 72 | debugMessage("Parsed input data:", string(data)) |
| 73 | } |
| 74 | |
| 75 | a.CreatedAt = issue.CreatedAt.Time |
| 76 | a.IssueNumber = *issue.Number |
| 77 | a.Account = a.stringSection("Account URL", true, ParseAccountURL) |
| 78 | a.boolSection("Non-commercial confirmation", true, ParseCheckbox, IsChecked) |
| 79 | |
| 80 | a.Project.IsTeam = a.boolSection("Team application", false, ParseCheckbox) |
| 81 | a.Project.IsEvent = a.boolSection("Event application", false, ParseCheckbox) |
| 82 | |
| 83 | isProject := !a.Project.IsTeam && !a.Project.IsEvent |
| 84 | |
| 85 | a.Project.Name = a.stringSection("Project name", true, ParsePlainString) |
| 86 | a.Project.Description = a.stringSection("Short description", true, ParsePlainString) |
| 87 | a.Project.Contributors = a.intSection("Number of team members/core contributors", true, ParsePlainString) |
| 88 | a.Project.HomeURL = a.stringSection("Homepage URL", true, IsURL) |
| 89 | a.Project.RepoURL = a.stringSection("Repository URL", false, IsURL) |
| 90 | a.Project.LicenseType = a.stringSection("License type", isProject, ParsePlainString) |
| 91 | a.Project.LicenseURL = a.stringSection("License URL", isProject, IsURL) |
| 92 | a.boolSection("Age confirmation", isProject, ParseCheckbox, When(isProject, IsChecked)) |
| 93 | |
| 94 | a.Applicant.Name = a.stringSection("Name", true, ParsePlainString) |
| 95 | a.Applicant.Email = a.stringSection("Email", true, IsEmail) |
| 96 | a.Applicant.Role = a.stringSection("Project role", true) |
| 97 | a.Applicant.ID = *issue.User.ID |
| 98 | |
| 99 | a.stringSection("Profile or website", false, IsURL) |
| 100 | a.stringSection("Additional comments", false) |
| 101 | |
| 102 | a.CanContact = a.boolSection("Can we contact you?", false, ParseCheckbox) |
| 103 | |
| 104 | if isTesting() { |
| 105 | debugMessage("Application data:", string(a.GetData())) |
| 106 | } |
| 107 | |
| 108 | for _, err := range a.validator.Errors { |
| 109 | a.Problems = append(a.Problems, fmt.Errorf(err.Error())) |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | func (a *Application) IsValid() bool { |